xxxxxxxxxx
29
/*
circle collision example
4.15.2024
*/
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
button(200, 200, 100, 'yellow');
button(100, 100, 50, 'blue');
button(300, 300, 200, 'purple');
}
function button(x, y, s, c) {
// calculate distance between circle origin and mouse
var d = dist(x, y, mouseX, mouseY);
if (d < s / 2) {
fill(c);
} else {
fill('white');
}
circle(x, y, s);
}