xxxxxxxxxx
42
let targetSize = 10;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
let aim = {
x: mouseX,
y: mouseY,
r: targetSize
};
noStroke();
fill(0, 255, 0);
circle(aim.x, aim.y, aim.r);
let target = {
x: width / 2,
y: height / 2,
r: targetSize
};
noFill();
stroke(255, 0, 0);
circle(target.x, target.y, target.r);
line(target.x - target.r, target.y, target.x + target.r, target.y);
line(target.x, target.y - target.r, target.x, target.y + target.r);
let targetDistance = dist(target.x, target.y, aim.x, aim.y);
if(targetDistance < target.r/2 + aim.r/2) {
noStroke();
fill(0, 0, 255);
circle(target.x, target.y, target.r);
}
}