MitraM 
		
		YaBB Newbies
		 
		Offline 
		
		
		Posts: 5
		
		
		
		
 
	 
	
		
			
				Slow down movement of connected "boids"  
				 Mar 25th , 2010, 1:58pm 
			 
			
				
	  
			 
		
		
			hi, i tried to introduce a button into my code that controls displaying the network-lines. that worked. the next step is now to slow down movement of connected boids, so that the pattern of the connected boids becomes stable after a while. any ideas?? THX! int mode = 0;  int gravitymode=0; int n = 25;            // amount of boids int p = 25; int o = 25; int s = 25; int a = 25; float cDist = 50;      // length of connecting lines PImage imgred;    float inc = 0.01; Boids[] boids = new Boids[n];                  // array red int canvasX = 700;     // canvas size x-direction  int canvasY = 500;     // canvas size y-direction  void keyPressed(){     if (key==' '){      noLoop();   }     if (key=='m'){      loop(); }   if (key=='h'){     mode=1;  }    if (key=='s'){     mode=0;  } if (key=='g'){     gravitymode=1;  }    if (key=='r'){     gravitymode=0;  } } void setup() {       size(canvasX, canvasY);  smooth();    for (int i = 0; i < n; i++) {      // boids red   boids[i] = new Boids(random(50,width-50),random(50,height-50));  }   imgred = loadImage("particlered.png");         }   void draw() {  background(0);  //stroke(234,45,65);   //strokeWeight(1);    for (int i = 0; i < n; i++) {      // boids red update - display    if (mode==0){         boids[i].drawLine();      boids[i].update();        boids[i].display();    }else{        boids[i].drawnoLine();      boids[i].gravityupdate();          boids[i].display(); }  } } class Boids{      float ptsX;    float ptsY;    float posX;    float posY;   float posYY;     float posXX;    float ptsYY;    float ptsXX;      float inc = 0.001;     // move increasement every loop   float inc2 =0.00001;         Boids (float _ptsX, float _ptsY){       ptsX = _ptsX;   ptsY = _ptsY;   posX = ptsX;   posY = ptsY;        // posXX = ptsXX;   //posYY = ptsYY; } void update(){ posX = noise(ptsX) * canvasX; posY = noise(ptsY) * canvasY; ptsX+=inc; ptsY+=inc; }    void gravityupdate(){  for (int i = 0; i < n-1; i++) {   Boids b=boids[i];      if (dist(posX, posY, b.posX, b.posY) > cDist) {           posX = noise(ptsX) * canvasX;          posY = noise(ptsY) * canvasY;          ptsX+=inc;          ptsY+=inc;          } else {             posX=300;            posY=300;                       //posX =posXX;            //posY =posYY;            //posXX+=inc2;            //ptsYY+=inc2; //posXX=posXX+1; //posYY=posYY+1; }     }    }    void display() {             // rendering settings for boids    stroke (255);    strokeWeight(1);       imageMode(CENTER);   image(imgred, posX, posY);     //noStroke();   // ellipseMode(CENTER);   // fill(random (240,250), random (70,80), random (10,20),200);  //  ellipse(posX, posY, 15,15);    } void drawLine() {     for (int i = 0; i < n-1; i++) {     Boids b=boids[i];       if (dist(posX, posY, b.posX, b.posY) < cDist) {          line(posX, posY, b.posX, b.posY);        }      }    }     void drawnoLine() { } }