xxxxxxxxxx
26
// modified p5.js reference example pixel array
function setup() {
createCanvas(500, 400);
//pixelDensity(1); // fix for high density displays
}
function draw() {
loadPixels();
let d = pixelDensity();
for (let y = 0; y < height * d; y++) {
for (let x = 0; x < width * d; x++) {
let index = (x + y * width *d) * 4;
// Red.
pixels[index] = x;
// Green.
pixels[index + 1] = y;
// Blue.
pixels[index + 2] = random(x, y);
// Alpha.
pixels[index + 3] = 255;
}
}
updatePixels();
}