xxxxxxxxxx
33
// radius of the circle
let radius = 15;
function setup() {
createCanvas(400, 400);
}
function draw() {
// clear the canvas
background(220);
// X and Y coordinates of the circle
let centerX = 100;
let centerY = 100;
// If the left mouse button is pressed...
if (mouseIsPressed && mouseButton === LEFT)
{
// As long as the mouse button is held, update the radius
// The radius equals the distance from the center to the mouse position
radius = dist(centerX, centerY, mouseX, mouseY);
}
// Draw a circle at the chosen center with the chosen radius
circle(centerX, centerY, radius * 2);
// Draw a small dot at the center of the circle
circle(centerX, centerY, 3);
// Print the center and radius in the top-left corner
text("Center X: " + centerX, 4, 16);
text("Center Y: " + centerY, 4, 32);
text("Radius: " + radius, 4, 48);
}