int ALPH = 0x80000000; int NUM_PARTICLES = 8192; int NUM_ATTRACTORS = 6; float damp = 0.9; float accel = 10.0; color[] colours = { ALPH | 0x00ffff00, ALPH | 0x00ff8000, ALPH | 0x00ffff00, ALPH | 0x00ff8000, ALPH | 0x00ffff00, ALPH | 0x00ff8000, ALPH | 0x00ffffff }; //ALPH | 0x00EBFABB, ALPH | 0x00A3AD82, ALPH | 0x00FADFBB, ALPH | 0x00AD9B82, ALPH | 0x00050505, ALPH | 0x00FAFAFA }; Particle[] particle; Attractor[] attractor; class Attractor { float x,y; Attractor() { x = random(width); y = random(height); } } class Particle { float x,y,vx,vy,px,py; Particle() { init(); } void init() { x = px = random(width); y = py = random(height); vx = random(-accel/2,accel/2); vy = random(-accel/2,accel/2); } void step() { for (int i = 0; i < attractor.length; i++) { float d2 = sq(attractor[i].x-x) + sq(attractor[i].y-y); if (d2 > 0.1) { vx += accel * (attractor[i].x-x) / d2; vy += accel * (attractor[i].y-y) / d2; } } px = x; py = y; x += vx; y += vy; vx *= damp; vy *= damp; // if (x < 0 || x > width || y < 0 || y > height) { // init(); // } } } void setup() { size(360,360); background(128,0,0); stroke(255); smooth(); strokeWeight(1); noFill(); attractor = new Attractor[NUM_ATTRACTORS]; for (int i = 0; i < attractor.length; i++) { attractor[i] = new Attractor(); } particle = new Particle[NUM_PARTICLES]; for (int i = 0; i < particle.length; i++) { particle[i] = new Particle(); } } void loop() { background(128,0,0); for (int j = 0; j < particle.length; j++) { stroke(colours[j%colours.length]); line(particle[j].x,particle[j].y,particle[j].px,particle[j].py); particle[j].step(); } } void mousePressed() { saveFrame(); background(128,0,0); for (int i = 0; i < attractor.length; i++) { attractor[i] = new Attractor(); } }