// Simple Multi-Particle Collisions. // NOTE: // -- this compares positions in order N^2 time, which means very slow for many particles... // -- particles can get stuck together if they are born inside each other, or if // they enter the other, and when their velocity reverses due to the collision, they are // still inside their partner. you can fix this if you're clever. Blob balls[]; int nBalls; void setup(){ size(600,700); background(255); nBalls = 100; balls = new Blob[nBalls]; for (int i=0; i width){ px -= width; } while (px < 0){ px += width; } while (py > height){ py -= height; } while (py < 0){ py += height; } } } //------------------------- class Blob extends PhysicalThing { boolean collide; float R; // radius color myColor; Blob(float x, float y){ px = x; py = y; vx = vy = 0; R = random(4, 7); collide = false; myColor = color(0, random(255), random(255)); } void handleCollisionWithOthersInTheArray (Blob[] arr, int num, int me){ for (int i=0; i