xxxxxxxxxx
36
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
stroke(255, 0, 255);
line(0, 0, width, height);
//something to show the pixel color of the pixel
//which the mouse is over
stroke(255);
fill(getPixel(mouseX, mouseY));
rect(width / 2 - 10, height / 2 - 10, 20, 20);
}
function getPixel(x, y) {
loadPixels();
var xy = (x + y * width) * 4;
return color(
pixels[xy],
pixels[xy + 1],
pixels[xy + 2],
pixels[xy + 3]
);
}
function setPixel(x, y, color) {
loadPixels();
var xy = (x + y * width) * 4;
pixels[xy] = red(color);
pixels[xy + 1] = green(color);
pixels[xy + 2] = blue(color);
pixels[xy + 3] = alpha(color);
updatePixels();
}