xxxxxxxxxx
55
var catImage;
function preload() {
catImage = loadImage("cat.jpg");
}
function setup() {
createCanvas(catImage.width, catImage.height);
pixelDensity(1);
// loadPixels();
catImage.loadPixels();
// Making every other pixel green
for (let y = 0; y < height; y += 2) {
for (let x = 0; x < width; x += 2) {
let index = (x + width * y) * 4;
catImage.pixels[index + 0] = 0;
catImage.pixels[index + 1] = 255;
catImage.pixels[index + 2] = 0;
catImage.pixels[index + 3] = 255;
}
}
// Erasing line that is 10 pixels tall across middle
for (let y = height/2 - 5; y < height/2 + 5; y++) {
for (let x = 0; x < width; x++) {
let index = (x + width * y) * 4;
catImage.pixels[index + 0] = 0;
catImage.pixels[index + 1] = 0;
catImage.pixels[index + 2] = 0;
catImage.pixels[index + 3] = 0;
}
}
// Colored line blue that is 10 pixels wide down middle
for (let y = 0; y < height; y++) {
for (let x = width/2 - 5; x < width/2 + 5; x++) {
let index = (x + width * y) * 4;
catImage.pixels[index + 0] = 0;
catImage.pixels[index + 1] = 0;
catImage.pixels[index + 2] = 255;
catImage.pixels[index + 3] = 255;
}
}
catImage.updatePixels();
image(catImage, 0, 0);
}
function draw() {
}