int dimx = 800; int dimy = 500; int sweep = 0; int ncrawlers = 150; int bg = 255; Crawler[] crawlers= new Crawler[ncrawlers]; void setup() { size(dimx, dimy); for ( int i = 0; i < ncrawlers; i++ ) { crawlers[i] = new Crawler( dimx/2, dimy/2,random(0, 2.0*PI), random ( 1.2, 1.8 ) ); } background(bg); } void loop () { for ( int i = 0; i < ncrawlers; i++ ) { crawlers[i].go(); } trackm(); int div = int( dimy / 10 ); for ( int j = 0; j < 10; j ++ ) { bsweep(sweep + j * div ); } sweep = ( sweep + 1 ) % ( div ); } void trackm() { if ( mousePressed == true ) { for ( int i = 0; i < ncrawlers; i++ ) { crawlers[i].seek ( mouseX, mouseY ); } } } class Crawler { float x, y, vx, vy; float ang, v, angv; boolean bouncing; Crawler ( float nx, float ny, float nang, float nv ) { x = nx; y = ny; ang = nang; v = nv; vx = v * cos ( ang ); vy = v * sin ( ang ); angv = random ( -0.04, 0.04 ); bouncing = false; } void go () { x += vx; y += vy; if ( bouncing == false ) { strokeWeight(1.0); stroke ( #000000 ,24); line( x-vx, y-vy, x, y ); stroke ( #000000 ,16); float cl = max ( -12, min( 12 , 50 * angv ) ) ; line( x, y , x + cl * vy, y - cl * vx ); } bounce(); // tpoint ( int(x), int(y), #000000, 0.3 ); } void seek(int rx, int ry) { float dang = atan2 ( ry - y , rx - x ); while ( dang > ang + PI ) dang -= TWO_PI; while ( dang < ang - PI ) dang += TWO_PI; if ( abs(dang-ang) > 0.166 * PI ) { angv = 0.04 * ( dang - ang ); } } void bounce() { int inbound = 1; if ( x < 0 || x > dimx ) { vx *= -1; ang = atan2(vy, vx); inbound = 0; } if ( y < 0 || y > dimy ) { vy *= -1; ang = atan2(vy, vx); inbound = 0; } float on = red ( get(int(x),int(y))); if ( inbound == 1 && bouncing == false && on < 160 ) { ang = atan2(vy, vx); v = random ( 1.2, 1.8 ); if ( on < 96 ) { ang += PI; ang += random ( -0.3, 0.3 ); angv = random ( -0.02, 0.02 ); //tpoint ( int(x), int(y), #40FFFF, 0.7 ); } else { angv *= -1.05; //tpoint ( int(x), int(y), #FF4040, 0.7 ); } bouncing = true; } else { bouncing = false; } ang += angv; vx = v * cos (ang); vy = v * sin (ang); } } color blend ( color ac , color bc, float f ) { if ( f > 1.0 ) return bc; if ( f < 0.0 ) return ac; int r,g,b; r = int(red(ac) + (red(bc) - red(ac)) * f); g = int(green(ac) +(green(bc) - green(ac)) * f); b = int(blue(ac) + (blue(bc) - blue(ac)) * f); return color (r, g, b); } void bsweep(int y) { for ( int i = 0 ; i < dimx; i ++ ) { int y2 = (y+1) % dimy; color ac = get(i, y); color bc = get(i, y2); color rc = blend ( blend ( ac, bc, 0.2 ), color(bg,bg,bg), 0.15 ); set ( i, y, rc ) ; } } // translucent point // started from j.tarbell void tpoint(int x1, int y1, color myc, float a) { strokeWeight(1); stroke ( myc, int(a * 255.0)); point ( x1, y1 ); } // O