xxxxxxxxxx
42
let x;
let y;
let rot;
function setup() {
createCanvas(1000, 1000);
strokeWeight(7);
noCursor();
x = 500;
y = 500;
rot = 0;
}
function draw() {
background(map(dist(mouseX, mouseY, x, y), 500, 0, 255, 150), 0, map(dist(mouseX, mouseY, x, y), 500, 0, 150, 255), 150);
rot = atan2(mouseY - y, mouseX - x);
if (dist(mouseX, mouseY, x, y) < 10 && !mouseIsPressed) {
fill(100, 255, 100);
x = mouseX;
y = mouseY;
} else {
noFill();
}
if (!mouseIsPressed) {
x += cos(rot) * (dist(mouseX, mouseY, x, y) / 10);
y += sin(rot) * (dist(mouseX, mouseY, x, y) / 10);
} else {
fill(255, 20, 20);
}
push();
noFill();
circle(mouseX, mouseY, 75);
pop();
line(x, y, mouseX, mouseY);
stroke(0);
circle(x, y, 75);
}