The code snippet provided below is intended to set the color value of each pixel within the createGraphics object to red. However, the output only displays a gray background.
//////////////////////////////////////////////////////////
function setup() {
createCanvas(800, 600);
pixelDensity(1);
gp = createGraphics(width, height);
}
//////////////////////////////////////////////////////////
function draw() {
background(125);
gp.loadPixels();
for(var x = 0; x < width; x++){
for(var y = 0; y < height; y++){
var index = (width * y + x) * 4;
gp.pixels[index+0]= 255;
gp.pixels[index+1]= 0;
gp.pixels[index+2]= 0;
}
}
gp.updatePixels();
image(gp,0,0, width,height);
}