xxxxxxxxxx
43
let xc;
let yc;
function setup() {
createCanvas(600, 600);
angleMode(RADIANS);
}
function draw() {
noStroke();
background(220);
var diam1 = 400;
var radius1 = 200;
circle(width/2, height/2, diam1);
var mx = map(mouseX, 0, width, -300, 300);
var my = map(mouseY, 0, height, -300, 300);
push();
fill("black");
translate(width/2, height/2);
var distance = dist(width/2, height/2, mouseX, mouseY);
if(distance > 100) {
xc = mx * (200/distance) - (mx * (100/distance));
yc = my * (200/distance) - (my * (100/distance));
} else if(distance < -100) {
xc = mx * (200/distance) + (mx * (100/distance));
yc = my * (200/distance) + (my * (100/distance));
} else {
xc = mx;
yc = my;
}
circle(xc, yc, 200);
pop();
}