tmn


NodeSystem ns;
int num = 500;

ArrayList nodes;

void setup(){
background(255,5);

size(800,500);

int distance = 23;
ns = new NodeSystem(distance);
num = 500;
frameRate(1);
smooth();
}
void draw(){
noStroke();
fill(255);
rect(0,0,width,height);
// rect(0,0,width,height);
// rect(0,0,width,height);
// rect(0,0,width,height);

ns.init(num);

ns.run();
saveFrame("nodes-####.tif");
// noLoop();
}



class Node{

PVector pos;
float diam;
int cons = 0;

Node(PVector pos,float diam){
this.pos = pos;
this.diam = diam;
}


void show(){

fill(255);
// pushMatrix();
// translate(pos.x,pos.y,pos.z);
ellipse(pos.x, pos.y, diam, diam);
// sphere(diam);
// popMatrix();
}
}


class NodeSystem{
ArrayList nodes;
float distance;
NodeSystem(float dis){
this.distance = dis;

}



ArrayList init(int num){
nodes = new ArrayList();

for(int i = 0; i < num; i++){
float x = random(10, width - 10);
float y = random(10, height - 10);
//float z = random(0,500); // 3D
float diam = 1;
// PVector pos = new PVector(x,y,z); // 3D
PVector pos = new PVector(x,y);

nodes.add(new Node(pos,diam));
}

return nodes;
}


// run the nodesystem
void run(){

display();

}

// calculate the connections and draw the lines
void calcDrawConnections(Node n){
for(int i = 0; i < nodes.size(); i ++){

PVector v1 = n.pos;
PVector v2 = nodes.get(i).pos;
float d = PVector.dist(v1, v2);

if((d < distance + n.cons* 5) &&(d > 1)){

stroke(0,100);
n.cons++;
n.diam+= 0.5;
//line(v1.x , v1.y,v1.z,v2.x, v2.y,v2.z); // 3D
line(v1.x , v1.y,v2.x, v2.y);

}
}
}

// display the nodes and draw the connections
void display(){
Node n = null;
for(int i = 0; i < nodes.size(); i++){
n = nodes.get(i);
calcDrawConnections(n);
n.show();
}
} // end display


}