xxxxxxxxxx
27
function setup() {
createCanvas(256,256); // coordinates are always between 0-255 for colors
pixelDensity(1);
}
function draw() {
loadPixels();
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
var index = (x + y * width) * 4; // nested for loop, one for the x's and one for the y's
pixels[index + 0] = x;
// red value changes horizontally
pixels[index + 1] = random(255);
// green value random
pixels[index + 2] = y;
// blue value changes vertically
pixels[index + 3] = 255;
// no transparency
}
}
updatePixels();
}