xxxxxxxxxx
function setup() {
createCanvas(windowWidth, windowHeight);
ctr = [createVector(random()*windowWidth, random()*windowHeight),
createVector(random()*windowWidth, random()*windowHeight),
createVector(random()*windowWidth, random()*windowHeight)];
rad = [random()*100, random()*100, random()*100]
sel = [false, false, false];
}
function draw() {
background(255);
stroke(0)
for(let i=0; i<3; ++i) {
circle(ctr[i].x, ctr[i].y, rad[i]);
}
}
function mousePressed() {
let m = createVector(mouseX, mouseY);
for(let i=0; i<3; ++i) {
if(m.dist(ctr[i]) < rad[i]) {
sel[i] = true;
}
}
}
function mouseReleased() {
for(let i=0; i<3; ++i) {
sel[i] = false;
}
}
function mouseDragged() {
let pm = createVector(mouseX-pmouseX, mouseY-pmouseY);
for(let i=0; i<3; ++i) {
if(sel[i]) {
ctr[i].add(pm);
}
}
}
function mouseWheel(event) {
for(let i=0; i<3; ++i) {
if(sel[i]) {
rad[i] += event.delta * 0.1;
rad[i] = max(rad[i], 10);
}
}
}