/* A large field of colliding circles. When two circles strike each other, they will draw a line between them. This chain will continue for up to 4 circles. */ //import processing.opengl.*; Ball[] actors; // All items in our scene final int BALL_COUNT = 250; // Number of shapes set by assignment PGraphics target; void setup() { size(645,800, P3D); background(255); smooth(); noFill(); actors = new Ball[BALL_COUNT]; // Populate the field for(int i = 0; i < BALL_COUNT; i++) { actors[i] = new Ball(random(0, width), random(0,height)); actors[i].Spur(); //Give them an arbitrary direction } } void draw() { //Move the coords to the bottom left for easier to remember math. translate(0,height); scale(1,-1); // Collide all the actors against each other. for(int i = 0; i < BALL_COUNT; i++) { //Only the one's we haven't already checked for(int j = i+1; j < BALL_COUNT; j++) { if ( collide(actors[i], actors[j]) > 0 ) { engage(actors[i], actors[j]); } } } // Update all the actors // Because they cannot atomically edit each other, it is safe to draw as we go. for(int i = 0; i < BALL_COUNT; i++) { // Not timestamped because the image is the important part. // We want every step, regardless of speed. actors[i].Update(); actors[i].Display(); } } //make two balls reference each other void engage(Ball A, Ball B) { A.Entangle(B); B.Entangle(A); } //Overload line() to make it easier to read when drawing two points; void line(PVector A, PVector B) { line(A.x, A.y, B.x, B.y); } //Same for Bezier void bezier(PVector A, PVector B, PVector C, PVector D) { bezier(A.x, A.y, B.x, B.y, C.x, C.y, D.x, D.y); }