Line displayed two times with different value.
in
Programming Questions
•
10 months ago
Hey guys.
I'm trying to make a sketch where some balls move, and there is connections drawing between them.
I feel like I succeed to do it, but It seems to me that each connection (lines) are displayed two times. One time with the good positionning, and a second time with the positionning of the previous frame or something like this.
Here I set a low framerate to show this.
I would greatly appreciate if someone could help me pointing out what is the problem.
Thank you in advance.
I'm trying to make a sketch where some balls move, and there is connections drawing between them.
I feel like I succeed to do it, but It seems to me that each connection (lines) are displayed two times. One time with the good positionning, and a second time with the positionning of the previous frame or something like this.
Here I set a low framerate to show this.
I would greatly appreciate if someone could help me pointing out what is the problem.
- final int objNB = 8;
- final int circlesNB = 3;
- int taillemax = 90;
- int maxspeed = 5;
- Circle[] circles = new Circle[objNB];
- void setup()
- {
- size(1024,576);
- background(0);
- smooth();
- frameRate(15);
- for(int i = 0;i<objNB;i++)
- {
- circles[i] = new Circle(random(taillemax-10,taillemax));
- }
- }
- class Circle
- {
- float Xpos,Ypos;
- float Xspeed,Yspeed;
- float taille;
- float taille2;
- float taille3;
- Circle(float taillebase)
- {
- this(random(taillebase,width-taillebase),random(taillebase,height-taillebase),random(-maxspeed,maxspeed),random(-maxspeed,maxspeed),taillebase);
- }
- Circle(float x,float y, float sx, float sy, float r)
- {
- Xpos = x;
- Ypos = y;
- Xspeed = sx;
- Yspeed = sy;
- taille = r;
- taille2 = random(1,r);
- taille3 = random(1,r);
- }
- void drawlines()
- {
- for(int j=0; j<objNB; j++)
- {
- if (Xpos != circles[j].Xpos && Ypos != circles[j].Ypos){
- if (dist(Xpos,Ypos,circles[j].Xpos,circles[j].Ypos) < 350)
- {
- stroke(255,255,255);
- line(Xpos,Ypos,circles[j].Xpos,circles[j].Ypos);
- }
- }
- }
- }
- void move()
- {
- Xpos += Xspeed;
- if (Xpos < taille || Xpos > width - taille)
- {
- Xspeed = -Xspeed;
- Xpos += Xspeed;
- }
- Ypos += Yspeed;
- if (Ypos < taille || Ypos > height - taille)
- {
- Yspeed = -Yspeed;
- Ypos += Yspeed;
- }
- }
- void display()
- {
- noStroke();
- fill(255,255,255,20);
- ellipse(Xpos, Ypos, taille * 2, taille * 2);
- ellipse(Xpos, Ypos, taille2 * 2, taille2 * 2);
- ellipse(Xpos, Ypos, taille3 * 2, taille3 * 2);
- }
- }
- void draw()
- {
- background(0);
- for(int i = 0;i<objNB;i++)
- {
- circles[i].drawlines();
- circles[i].display();
- circles[i].move();
- }
- }
Thank you in advance.
1