// blur adapted from super fast blur by Mario Klingemann (http://incubator.quasimondo.com/processing/superfastblur.pde) int NUM_PARTICLES = 8192; int NUM_ATTRACTORS = 4; color[] colours = { #ffffff, #000000, #ffa0a0, #ffa0ff }; int ALPH = 10; Particle[] particle; Particle[] attractor; class Particle { float damp, accel; float x,y,vx,vy,px,py; Particle() { damp = 0.9999; accel = 1; x = px = random(width); y = py = random(height); vx = random(-accel/2,accel/2); vy = random(-accel/2,accel/2); } void step() { forces(); move(); } void forces() { 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; } } } void move() { px = x; py = y; x += vx; y += vy; vx *= damp; vy *= damp; } } class Attractor extends Particle { Attractor() { super(); damp = 0.5; accel = 10; } void forces() { super.forces(); float d2 = sq((width/2)-x) + sq((height/2)-y); if (d2 > 0.1) { vx += accel * ((width/2)-x) / d2; vy += accel * ((height/2)-y) / d2; } } void move() { super.move(); if (x < 0 || y < 0 || x > width || y > height) { x = px = random(width); y = py = random(height); } } } void setup() { size(360,360); background(128); stroke(255); // smooth(); noFill(); attractor = new Particle[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(); particle[i].x = attractor[i%attractor.length].x; particle[i].y = attractor[i%attractor.length].y; } init_blur(2); setAlpha(colours, ALPH); } void loop() { if (keyPressed) background(128); else fastblur(); for (int j = 0; j < particle.length; j++) { particle[j].step(); stroke(colours[j%colours.length]); line(particle[j].x,particle[j].y,particle[j].px,particle[j].py); } for (int j = 0; j < attractor.length; j++) { attractor[j].step(); stroke(0,4); line(attractor[j].x,attractor[j].y,attractor[j].px,attractor[j].py); } } void mousePressed() { //background(255); for (int i = 0; i < attractor.length; i++) { attractor[i] = new Attractor(); } for (int i = 0; i < particle.length; i++) { particle[i] = new Particle(); particle[i].x = attractor[i%attractor.length].x; particle[i].y = attractor[i%attractor.length].y; } } void keyPressed() { setAlpha(colours, 255); } void keyReleased() { setAlpha(colours, ALPH); } int radius; int w, h, wm, hm, wh, div; int r[]; int g[]; int b[]; int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw; int vmin[]; int vmax[]; int dv[]; void init_blur(int rad) { radius = rad; w = width; h = height; wm = w-1; hm = h-1; wh = w*h; div = radius+radius+1; r = new int[wh]; g = new int[wh]; b = new int[wh]; vmin = new int[max(w,h)]; vmax = new int[max(w,h)]; dv = new int[256*div]; for (i=0;i<256*div;i++){ dv[i]=(i/div); } } void fastblur(){ 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>> 8); } }