How to erase lines between circles?
in
Programming Questions
•
1 year ago
Hi guys, i have classic moving circles and line between them if they are less than certain distance away.
Then i make an eraser with the mouse (as you see in mouseMoved).
Now the problem is: i did erase the circles with my mouse, but those lines between them didn't.
So how can i erase the circle and meanwhile erase the line related to it ???
- int maxCircles = 20;
- Circle[] circles = new Circle[maxCircles];
- void setup(){
- size(400,400);
- smooth();
- for(int i = 0; i < maxCircles; i++) circles[i] = new Circle(random(width),random(height),random(20,40));
- }
- void draw(){
- background(255);
- for(int i = 0; i < maxCircles; i++){
- circles[i].update();
- circles[i].display();
- for(int j = 0; j < maxCircles; j++){
- if(dist(circles[i].x,circles[i].y,circles[j].x,circles[j].y)<40){
- stroke(0,50);
- line(circles[i].x,circles[i].y,circles[j].x,circles[j].y);}
- }
- }
- }
- void mouseMoved(){
- for(int i = 0; i < maxCircles; i++){
- float distance = dist(mouseX,mouseY,circles[i].x,circles[i].y);
- if(distance<20){
- circles[i].r--;
- }
- }
- }
- class Circle{
- float x,y,vx,vy,r;
- Circle(float ax,float ay,float ar){
- x = ax;
- y = ay;
- r = ar;
- vx = random(-.1,.1);
- vy = random(-.1,.1);
- }
- void update(){
- x += vx;
- y += vy;
- r=constrain(r,0,40);
- }
- void display(){
- noStroke();
- fill(0,50);
- ellipse(x,y,r,r);
- }
- }
Many thanks.
1