xxxxxxxxxx
29
let target;
let colours;
function setup() {
createCanvas(400, 400);
target = new Target();
colours = {
white: color(255),
black: color(0),
}
}
function draw() {
background(0);
if (mouseIsPressed) {
let distance = dist(mouseX, mouseY, target.x, target.y);
let amount = map(distance, 0, 100, 0, 1);
let colour = lerpColor(colours.white, colours.black, amount);
background(colour);
if (distance < 5) {
background(0, 255, 0);
}
}
}