Skip to content

Two new examples for loadPixels #2793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
44 changes: 44 additions & 0 deletions src/image/pixels.js
Original file line number Diff line number Diff line change
@@ -496,6 +496,26 @@ p5.prototype.get = function(x, y, w, h) {
* @example
* <div>
* <code>
* function setup() {
* pixelDensity(1);
* background(244, 122, 158);
* loadPixels();
* for (var y = 0; y < height; y = y + 5) {
* for (var x = 0; x < width; x = x + 5) {
* var index = (x + y * width) * 4;
* pixels[index] = 255;
* pixels[index + 1] = 255;
* pixels[index + 2] = 255;
* pixels[index + 3] = 255;
* }
* }
* updatePixels();
* }
* </code>
* </div>
*
* <div>
* <code>
* var img;
* function preload() {
* img = loadImage('assets/rockies.jpg');
@@ -517,6 +537,30 @@ p5.prototype.get = function(x, y, w, h) {
* @alt
* two images of the rocky mountains. one on top, one on bottom of canvas.
*
*
* <div>
* <code>
* var img;
* function preload() {
* img = loadImage('assets/rockies.jpg');
* }
* function setup() {
* image(img, 0, 0);
* loadPixels();
* for (var y = 0; y < height; y++) {
* for (var x = 0; x < width; x++) {
* var index = (x + y * width) * 4;
* var sum_of_pixels = pixels[index] + pixels[index + 1] + pixels[index + 2];
* pixels[index] = sum_of_pixels / 3;
* pixels[index + 1] = sum_of_pixels / 3;
* pixels[index + 2] = sum_of_pixels / 3;
* }
* }
* updatePixels();
* }
* </code>
* </div>
*
*/
p5.prototype.loadPixels = function() {
this._renderer.loadPixels();