xxxxxxxxxx
40
let myImage;
let cat;
function preload() {
cat = loadImage("cat.jpg");
}
function setup() {
createCanvas(cat.width, cat.height);
background("red");
pixelDensity(1);
myImage = createImage(width, height);
cat.loadPixels();
myImage.loadPixels();
for (let i = cat.width * 4; i < myImage.pixels.length; i += 4) {
myImage.pixels[i] = cat.pixels[i];
myImage.pixels[i + 1] = cat.pixels[i + 1];
myImage.pixels[i + 2] = cat.pixels[i + 2];
myImage.pixels[i + 3] = cat.pixels[i + 3];
}
//erase the middle line code
for (let i = 135 * cat.width * 4; i < 136 * cat.width * 4; i++) {
myImage.pixels[i] = 0;
}
// get, set
for (let x = 0; x < width; x++) {
myImage.set(x, height / 2, [255, 0, 0, 255]);
}
myImage.updatePixels();
image(myImage, 0, 0);
}
function draw() {}