xxxxxxxxxx
28
// https://idmnyu.github.io/p5.js-image/ REFER TO INDEXING SECTION TO UNDERSTAND WHAT I MEAN BY PIXEL MADE UP BY 4 POSITIONS
function setup() {
background (220);
let pink = color(255, 102, 204);
loadPixels();
let d = pixelDensity();
// let var = (x + y * width)*4; THIS IS THE INDEX OF PIXELS v
let halfImage = 4 * (width * d) * ((height / 2) * d);
for (let i = 0; i < halfImage; i += 4) { // each pixel made up of 4 positions (r, g, b, a), so it skips over 4 to skip over 1 pixel
// in this case (r, g, b, a) = (0, 1, 2, 3)
pixels[i + 0] = red(pink); // so 0 = r
pixels[i + 1] = green(pink); // so 1 = g
pixels[i + 2] = blue(pink); // so 2 = b
pixels[i + 3] = blue(pink); // so 3 = a
// TO CLARIFY:
// red = pixels[index+0];
// green = pixels[index+1];
// blue = pixels[index+2];
// alpha = pixels[index+3];
}
updatePixels();
}