xxxxxxxxxx
39
let cat;
function preload() {
cat= loadImage("cat.jpg");
}
function setup(){
createCanvas(480, 270);
pixelDensity(1);
cat.loadPixels();
//Make every other pixel green.
for (let x=0; x<width; x++){
for(let y=0; y<height; y++){
var index=(x+y*width)*8;
cat.pixels[index]=0;
cat.pixels[index+1]=255;
cat.pixels[index+2]=0;
cat.pixels[index+3]=255;
}
}
//Erase a line that is 10 pixels tall across the middle of it.
for (let y=height/2-5;y<height/2+5;y++){
for (let i=0;i<width;i++){
cat.set(i,y,[0,0,0,0]);
}
}
//Turn a line that is 10 pixels wide down the middle of it blue.
for (let y=width/2-5;y<width/2+5;y++){
for (let i=0;i<height;i++){
cat.set(y,i,[0,0,255,255]);
}
}
cat.updatePixels();
}
function draw(){
background(50);
image(cat,0,0);
}