int ALPH = 0x0f000000; int BLUR_RADIUS = 2; int NUM_PARTICLES = 8192; int NUM_ATTRACTORS = 5; float damp = 0.99999; float accel = 0.2; color[] colours = { ALPH | 0x00A3D39C, ALPH | 0x0086AD80, ALPH | 0x00698764, ALPH | 0x00C9D49D, ALPH | 0x00A4AD80, ALPH | 0x00808764, ALPH | 0x002B2B2B, ALPH | 0x00D4D4D4, ALPH | 0x00000000 }; 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() { x = px = random(width); y = py = random(height); // vx = random(1) > 0.5 ? random(-15,-12) : random(12,15); // vy = random(1) > 0.5 ? random(-15,-12) : random(12,15); vx = random(-accel/2,accel/2); vy = random(-accel/2,accel/2); } void step() { px = x; py = y; 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; } } x += vx; y += vy; vx *= damp; vy *= damp; } } void setup() { size(360,360); background(0); 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() { fastblur(g,BLUR_RADIUS); 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() { for (int i = 0; i < attractor.length; i++) { attractor[i] = new Attractor(); } } // from http://incubator.quasimondo.com/processing/superfastblur.pde (thanks Mario!) void fastblur(BImage img,int radius){ if (radius<1){ return; } int w=img.width; int h=img.height; int wm=w-1; int hm=h-1; int wh=w*h; int div=radius+radius+1; int r[]=new int[wh]; int g[]=new int[wh]; int b[]=new int[wh]; int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw; int vmin[] = new int[max(w,h)]; int vmax[] = new int[max(w,h)]; int[] pix=img.pixels; int dv[]=new int[256*div]; for (i=0;i<256*div;i++){ dv[i]=(i/div); } yw=yi=0; for (y=0;y>16; gsum+=(p & 0x00ff00)>>8; bsum+= p & 0x0000ff; } for (x=0;x>16; gsum+=((p1 & 0x00ff00)-(p2 & 0x00ff00))>>8; bsum+= (p1 & 0x0000ff)-(p2 & 0x0000ff); yi++; } yw+=w; } for (x=0;x