int dimx = 800; int dimy = 500; int sweep = 0; int ncrawlers = 64; int crawlnum = 2; int bg = 0; float noiseoff = 0; BFont mFont; Crawler[] crawlers= new Crawler[ncrawlers]; String line = "what a nice day for a walk with you... "; void setup() { size(dimx, dimy); for ( int i = 0; i < ncrawlers; i++ ) { crawlers[i] = new Crawler( dimx/2 , dimy/2 , 0 , random ( 1.0, 5.0 ) ); } background(bg); mFont = loadFont ( "Base_5.vlw" ); } void loop () { for ( int i = 0; i < crawlnum; 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 ); noiseoff += 0.001; } 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; boolean loaded; int lchild; boolean connect; float daccum; int dc; 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; loaded = false; lchild = 0; daccum = 0; dc = 0; } void render() { if ( bouncing == false ) { strokeWeight(1.0); stroke ( 255, 255, 255 ,64); if ( loaded ) stroke ( 255,255,255,128 ); line( x-vx, y-vy, x, y ); if ( lchild > 0 && connect ) { float dx = crawlers[lchild].x - x; float dy = crawlers[lchild].y - y; line ( x, y , crawlers[lchild].x, crawlers[lchild].y ); if ( dx*dx + dy*dy > 8000 ) connect = false; } } /* if ( daccum > 10.0 ) { if ( abs(angv) < 0.1 ) { push(); translate ( x, y , 0 ); rotateZ( ang ); fill ( 128, 64, 32, 192 ); textFont(mFont, 18); text ( line.charAt(dc), 0, 0 ); pop(); dc = (dc+1) % line.length(); } while ( daccum > 10.0 ) daccum -= 10.0; } */ } void go () { x += vx; y += vy; daccum += v; render(); bounce(); } 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 spork( float nx, float ny, float nang ) { x = nx; y = ny; ang = nang; lchild = 0; } 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; } angv = ( 0.5 - noise ( 0.02 * x , 0.02 * y , noiseoff ) ) ; if ( !loaded && abs (angv) > 0.25 ) loaded = true; if ( loaded && abs (angv) < 0.05 ) { float curl = random ( -0.1, 0.1 ); if ( lchild > 0 ) { crawlers[lchild].spork ( x, y , ang + curl ); connect = true; } else if ( crawlnum < ncrawlers ) { crawlers[crawlnum].spork ( x, y , ang + curl ); lchild = crawlnum; connect = true; crawlnum++; } loaded = false; } v = 4.0 - 4.0 * abs ( angv ); angv *= 0.8; ang += angv; // line ( x, y, x , y - 100 * noise ( 0.03 * x , 0.03 * y ) ) ; // line ( x, y, x , y - 100 ) ; 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.4 ), color(bg,bg,bg), 0.1 ); 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