xxxxxxxxxx
39
let centerX, centerY; // center of the circle
let radius; // radius of the circle
let isDragging = false; // flag to indicate if the mouse is being dragged
function setup() {
createCanvas(400, 400);
background(220);
}
function draw() {
if (isDragging) {
// update the radius based on the distance between the center and the mouse position
radius = dist(centerX, centerY, mouseX, mouseY);
// draw the circle with the current radius
ellipse(centerX, centerY, 2 * radius, 2 * radius);
}
}
function mousePressed() {
// set the center of the circle to the current mouse position
centerX = mouseX;
centerY = mouseY;
// set the initial radius to 0
radius = 0;
// set the dragging flag to true
isDragging = true;
}
function mouseReleased() {
// set the dragging flag to false
isDragging = false;
// draw the final circle with the last set radius
ellipse(centerX, centerY, 2 * radius, 2 * radius);
}