We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to not display the connecting lines
Page Index Toggle Pages: 1
how to not display the connecting lines (Read 342 times)
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);
     }
   }
 }
 

}




Re: how to not display the connecting lines
Reply #1 - Mar 23rd, 2010, 4:46pm
 
i had a little trouble reading it but you could try doing

boolean draw=True;

keyPressed(){
if (key=="d"){
  if(draw){
    draw=False
   }
    else{
    draw=True
    }
}


////then in the draw() do...........

if(draw){

object.maydrawMethod();

}






Page Index Toggle Pages: 1