float maxDistance = 400; int numVehicles = 104; int numSources = 4; Vehicle [] v = new Vehicle[numVehicles]; Source [] s = new Source[numSources]; //Source s2; void setup() { size( 650,650 ); // sets the size of the environment frameRate(50); // sets the number of draw loops per second noStroke(); // sets the stroke on ellipses to none // this type of loop lets us perform some action to each vehicle in our array for( int i = 0; i averageDistance ) { minDistance = averageDistance; } direction = direction + distance1/turnSpeed * (1-distance1/maxDistance); direction = direction - distance2/turnSpeed * (1-distance2/maxDistance); } speed = (maxSpeed - ( maxSpeed * minDistance/maxDistance)); } } class Vehicle1 implements Vehicle{ float xPos; float yPos; float speed; float direction; color myColor; Vehicle1( float x, float y ) { xPos = x; yPos = y; speed = 2; direction = random(0,360); // the direction and myColor = color(0,0,0); // the color of every new // vehicle will be rando } void drawMyself( ) { fill ( myColor ); ellipse( xPos, yPos, 10, 10 ); } void update( Source [] s) { float dx = s[0].xPos - xPos; float dy = s[0].yPos - yPos; float distance1 = sqrt( dx*dx + dy*dy ); speed = maxSpeed - ( maxSpeed * distance1/maxDistance); } void updatePosition() { xPos = xPos + speed * cos( radians(direction) ); yPos = yPos - speed * sin( radians(direction) ); } } class Source { float xPos; float yPos; Source( float x, float y ) { xPos = x; yPos = y; } void drawMyself() { fill( 255, 0, 0 ); ellipse( xPos, yPos, 10, 10 ); } } class Sensor { float xPos; float yPos; Sensor( float x, float y ) { xPos = x; yPos = y; } void drawMyself() { fill( 240, 120, 0 ); ellipse( xPos, yPos, 2, 2 ); } void updatePosition( float x, float y ) { xPos = x; yPos = y; } }