MitraM
YaBB Newbies
Offline
Posts: 5
how to not display the connecting lines
Mar 23rd , 2010, 4:25pm
hi, i've tried to put into this code a button to turn on/off the connecting lines of the network. it seemed to be very easy in other codes... i have no idea why it is not working in this code...... any ideas?? thx! int o = 25; float cDist = 75; // length of connecting lines void keyPressed(){ if (key=='d'){ drawLine=!drawLine; } else { drawLine = drawLine; } } BoidsBlue[] boidsblue = new BoidsBlue[o]; int canvasX = 700; // canvas size x-direction int canvasY = 500; // canvas size y-direction void setup() { size(canvasX, canvasY); smooth(); for (int f = 0; f < o; f++){ boidsblue[f] = new BoidsBlue(random(50,width-50),random(50,height-50)); //initial position of each boid is defined here } } void draw() { background(255); //stroke(234,45,65); //strokeWeight(1); for (int f=0; f<o; f++){ boidsblue[f].update(); boidsblue[f].display(); boidsblue[f].drawLine(); } } class BoidsBlue{ float ptsX ; float ptsY ; float posX; float posY; float inc = 0.001; BoidsBlue(float _ptsX, float _ptsY){ // We cannot change these variables because we still need the extension of the code later on // still don't know what the [i] really means but has been in the original code all the time.... ptsX = _ptsX; ptsY = _ptsY; posX = ptsX; posY = ptsY; } void update(){//added update function, to enable movement [from original code] posX = noise(ptsX) * canvasX; posY= noise(ptsY) * canvasY; ptsX+=inc; //just another way to write ptsX=ptsX+inc ptsY+=inc; } void display() { stroke (random (10,15), random (120,130), random (185,195)); strokeWeight(0); //noStroke(); ellipseMode(CENTER); fill(random (10,15), random (120,130), random (185,195),200); ellipse(posX, posY, 16, 16); } void drawLine() { for (int f = 0; f < o-1; f++) { BoidsBlue bl=boidsblue[f]; if (dist(posX, posY, bl.posX, bl.posY) < cDist) { line(posX, posY, bl.posX, bl.posY); } } } }