Am working on a code using loops, basically what I want to do is draw a chain of circles that stretches from the center of the screen to the mouse position. but I can’t make the chain follow the mouse this is my code so far please help anyone
final float TARGET_SPACING = CIRCLE_DIAMETER * 0.75;
//One end of the chain (the "anchor point") will be the centre of the canvas.
float anchorX, anchorY; //Can't set until after size() is done.
void setup() {
size(500,500);
anchorX = width/2;
anchorY = height/2;
strokeWeight(2); //It looks better with thicker lines
stroke(255); //white lines
noFill(); //and hollow circles
}//setup
void draw() {
background(0);
float chainLenght= sqrt(sq(mouseX-anchorX) + sq(mouseY-anchorY));
float totalCircles=(chainLenght/TARGET_SPACING) +1;
round(totalCircles);
float circleArea = (totalCircles/CIRCLE_DIAMETER);
float AreaH=(mouseX/TARGET_SPACING);
float AreaV=(mouseY/TARGET_SPACING);
float exactCircleArea = sqrt(sq(anchorX + circleArea) + sq(anchorY + circleArea));
for(float circle=1; circle<=totalCircles; circle+=circleArea){
ellipse(anchorX+(circle*AreaH),anchorY+(circle*AreaV),CIRCLE_DIAMETER,CIRCLE_DIAMETER);
}
};