// Seung Joon Choi // http://epicure.graffity.net : underconstruction // epicure@hanmail.net // 2005.09.22. Particle[] ptcls; int n_ptcls; int h = 0; void setup() { size(640, 480, P3D); background(random(255), random(255), random(255)); noStroke(); n_ptcls = 50 + (int)random(150); ptcls = new Particle[n_ptcls]; if(random(1) > 0.5) { h = (int)(25 + random(220)); } else { h = 0; } for(int i = 0; i < n_ptcls; i++) { ptcls[i] = new Particle(random(width), random(height), 5 + random(10), h); } } void draw() { for(int i = 0; i < n_ptcls; i++) { if(i == 0) { //ptcls[i].Interact(mouseX, mouseY); ptcls[i].Interact(ptcls[n_ptcls-1].x, ptcls[n_ptcls-1].y); } else { ptcls[i].Interact(ptcls[i-1].x, ptcls[i-1].y); for(int j = 0; j < n_ptcls; j++) { int k = 0; float vx = 0; float vy = 0; if(i != j) { float dx = ptcls[i].x - ptcls[j].x; float dy = ptcls[i].y - ptcls[j].y; float d = sqrt(dx*dx + dy*dy); if(d < ptcls[i].r * 2) { vx += ptcls[j].vx; vy += ptcls[j].vy; k++; if(d < ptcls[i].r) { ptcls[i].x += dx * 0.02; ptcls[i].y += dy * 0.02; ptcls[j].x += -dx * 0.02; ptcls[j].y += -dy * 0.02; } } if(k != 0) { ptcls[i].vx += vx / (float)k * 0.05; ptcls[i].vy += vy / (float)k * 0.05; ptcls[i].vx *= 0.99; ptcls[i].vy *= 0.99; } } } } ptcls[i].Render(); } }