xxxxxxxxxx
51
let catImage;
let cat;
let myImage;
//anything you want to include from the cloud/elsewhere
function preload() {
cat = loadImage("cat.jpg");
}
function setup() {
background('red');
createCanvas(cat.width, cat.height);
pixelDensity(1);
//create an empty p5 iamge
myImage = createImage(width, height);
cat.loadPixels();
myImage.loadPixels();
for (let i = 0; i < myImage.pixels.length; i++) {
//red
myImage.pixels[i] = cat.pixels[i];
//green
myImage.pixels[i + 1] = cat.pixels[i + 1];
//blue
myImage.pixels[i + 2] = cat.pixels[i + 2];
//alpha
myImage.pixels[i + 3] = cat.pixels[i];
}
//erase the middle line code
for(let c = 135*cat.width*4 ; c<136*cat.width*4; c++){
myImage.pixels[c]=0
}
//get and set
// for(x=0;x<width; x++){
// myImage.set(x,height/2, [0,0,0,0]);
// }
function draw() {
// background(220);
//image(cat, 0, 0);
//green
// myImage.pixels[i + 1] = cat.pixels[i + 1];
//blue
// myImage.pixels[i + 2] = cat.pixels[i + 2];
//alpha
// myImage.pixels[i + 3] = cat.pixels[i];
}
myImage.updatePixels();
image(myImage, 0, 0);
}