-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
createGraphics and loadPixels #1403
Comments
As far as I understand it, loadPixels() only works with the default display window (I think there are plans to change this so that it applies to multiple buffers, @lmccart ? ) so using loadPixels won't have any effect on your buffer object's pixel array. As an aside, writing to the buffer would require you do to something like this: buffer.background(64,255,128); |
Got it. As I said, I was using it the way I've used it in Processing, but now I know it that it doesn't apply to multiple buffers. Thanks! |
|
I have a new release coming hopefully today that includes the latest pixel fixes, so I'd wait a day and try with tthat one. |
Hi all,
Not sure if this is a bug, but its not documented and functions very differently than Processing, which is confusing. If you use createGraphics() to draw an off-screen buffer (called buffer below), then use buffer.loadPixels(), the pixels() array gets updated with those pixels, not buffer.pixels() like in Processing. The example below demonstrates this. If this is the intended function -- it would be helpful if it was documented somewhere. Thanks!
Here is an example:
// ----------------------
var buffer;
var d;
function setup() {
createCanvas(200, 200);
buffer = createGraphics(width,height);
d = pixelDensity();
}
function draw() {
var index = (0 * width + 0) * (d * 4);
buffer.background(0, 0, 0);
buffer.loadPixels();
background(64, 255, 128);
console.log(buffer.pixels[0]); // should this be 0 (as in Processing)? logs undefined
console.log(buffer.pixels[1]); // same
console.log(buffer.pixels[2]); // same
console.log(pixels[0]); // should this be 64? logs as 0
console.log(pixels[1]); // should this be 255? logs as 0
console.log(pixels[2]); // should this 128? logs as 0
noLoop();
}
The text was updated successfully, but these errors were encountered: