xxxxxxxxxx
35
let img;
// use preload to load the image you uploaded
function preload() {
img = loadImage("fruits.png");
}
function setup() {
createCanvas(512, 512);
}
function draw() {
// draw an image
image(img, 0, 0, width, height);
// get a subsection
let section0 = img.get(0, 0, 250, 150);
// use tint to change color, push/pop to not affect other stuff
push();
tint(255, 0, 200);
image(section0, 0, 0);
pop();
// get another subsection
// want to draw it in middle of screen so need center mode
// push/pop for that
// and subtract half of the desired width/height from the mouse position
// in order to get the center of the section around the mouse
let section1 = img.get(mouseX - 100, mouseY - 100, 200, 200);
push();
imageMode(CENTER);
image(section1, width / 2, height / 2);
pop();
}