I'm trying to make an animation similar to the header on this site, where circles drift upwards connecting with others close by. I'm using a vector to store all the circle instances and when I loop through to display everything in the vector sometimes all the circles aren't displayed. This leads to them "flickering". Any help/ideas of why this would happen are appreciated.
Thank You (sorry it's so messy right now)
Code://Drifting Nodes
//5.19.2009
//===== Warning: code is very messy =====
Vector pluses = new Vector();
color backGround = color(75); //Background color
//PFont font;
float connectionDist = 135;
void setup()
{
size(1280, 720);
smooth();
frameRate(30);
//font = loadFont("FreeSansBold-22.vlw");
//textFont(font, 22);
strokeWeight(2);
}
void draw()
{
background(backGround);
for (int i=0;i<pluses.size();i++)
{
plus p = (plus)pluses.elementAt(i);
/*
for(int k=0;k<pluses.size();k++)
{
plus q = (plus)pluses.elementAt(k);
if( dist(p.x,p.y,q.x,q.y) < connectionDist)
{
stroke(0, map(dist(p.x,p.y,q.x,q.y),0,connectionDist,255,0));
line(p.x,p.y,q.x,q.y);
}
}
*/
p.display();
if(p.alive == false)
{
pluses.remove(i);
}
}
if(frameCount % 8 == 0) //Speed of plus spawn (lower number yields a faster spawn rate)
{
makePlus();
}
//========== Save IMG Sequence ==========
saveFrame("DriftingNodes-####.png");
//print("Seconds running: ");
println(frameCount);
//=======================================
//fill(0);
//text("Drifting Nodes Beta 5/19/2009",10,25);
}
void makePlus()
{
color col;
//col = color(random(235, 255), random(110, 191), random(8, 41)); //Color range for pluses
col = color(random(0, 170), 220, random(0, 200)); //Green
//col = color(random(224, 255), random(80, 163), random(5, 19)); //Orange
//col = color(random(20, 50), random(77, 165), random(180, 240)); //Blue
//col = color(random(255), random(255), random(255)); //All Colors
//col = color(random(50,110));
//col = color(random(100,255), random(200,230), random(200,230)); //Pastel
pluses.addElement(new plus(random(-50, width+50), height+50, random(0.60,1.85), col, random(0.75,1.65), random(-0.25,0.25)));
}
class plus
{
boolean alive;
float x, y;
float intialScale;
color col;
float changeSpeed, changeDirection;
//float alphaFade;
plus(float xpos, float ypos, float intialScale, color col, float changeSpeed, float changeDirection)
{
x=xpos;
y=ypos;
this.intialScale=intialScale;
alive=true;
this.col=col;
this.changeSpeed = changeSpeed;
this.changeDirection = changeDirection;
}
void display()
{
int connectionsCount = 0;
for(int k = 0; k < pluses.size(); k++)
{
plus p = (plus)pluses.elementAt(k);
if( dist(x, y, p.x, p.y) < connectionDist)
{
stroke(0, map(dist(x,y,p.x,p.y),0,connectionDist,255,0));//*alphaFade/255);
line(x,y,p.x,p.y);
connectionsCount++;
}
}
stroke(0);
fill(0);
ellipse(x,y,7*this.intialScale,7*this.intialScale);
stroke(0,90);
fill(this.col, 90);
ellipse(x,y,30*this.intialScale,30*this.intialScale);
// Display number of connections each node is holding
// stroke(0);
// fill(0);
// connectionsCount-=1;
// text(connectionsCount,x+2,y-5);
// alphaFade = map(y, height+100, -100, 255, 0);//255 * (1 - (y / height));
y-=(this.intialScale/2)*this.changeSpeed;
x+=changeDirection;
if(y < -100 || x < -30 || x > width+30)
{
alive = false;
}
}
}