//import processing.opengl.*; int NUMACTORS = 15; int i = 0; int rNum1, rNum2; Actor actors[] = new Actor[NUMACTORS]; void setup(){ size(500,500,P3D); reset(); ellipseMode(CENTER_RADIUS); background(0); //smooth(); } void draw(){ if(keyPressed){ if(key == ' '){ reset(); } background(0); } for(i = 0; i < NUMACTORS; i++){ actors[i].step(); } } void reset(){ for(i = 0; i < NUMACTORS; i++){ actors[i] = new Actor(random(0,width), random(0,height), random(1,10), actors, NUMACTORS); //actors[i].attach((int)random(0,NUMACTORS-1) , (int)random(0,NUMACTORS-1)); actors[i].attach((i+1)%NUMACTORS, (NUMACTORS-(i-1))%NUMACTORS); } } class Actor{ float x,y,m; float rx,ry; float ax,ay; float fx,fy; Actor actors[]; int follow; int avoid; int NUMACTORS; float FK = -2; float AK = .010; float DAMP = .3; int STEPS = 50; float POINTALPHA = 50; int POINTCOLOR = 255; float POINTRADIUS = 1.; Actor(float x, float y, float m, Actor[] actors, int NUMACTORS){ this.x=x; this.y=y; this.m=m; this.actors = actors; } void attach(int follow, int avoid){ this.follow = follow; this.avoid = avoid; } void step(){ /*force = -k * (tempypos - rest_posy); // f=-ky accel = force / mass; // Set the acceleration, f=ma == a=f/m vely = damp * (vely + accel); // Set the velocity tempypos = tempypos + vely; // Updated position force = -k * (tempxpos - rest_posx); // f=-ky accel = force / mass; // Set the acceleration, f=ma == a=f/m velx = damp * (velx + accel); // Set the velocity tempxpos = tempxpos + velx; // Updated position */ //f = k*(distance to followed) - k*(distance to avoided) for(int i = 0; i