// mikkel . crone . koser / www.beyondthree.com // http://proce55ing.beyondthree.com // vector worms 0.1 // july 2003, rev 0056 // ported to 0062, sept. 2003 // (and yeah, well, also added blur from seb!) final int WIDTH=400; final int HEIGHT=400; int blurCount = 0; float blurCountInc = 1; int aa = 40; int rr = 255; int gg = 255; int bb = 0; int rgbSpeed = 4; worm[] Worms; static int POP = 20; int stepDist; int r; int g; int b; void setup(){ size(400, 400); background(0); //framerate(25); stroke(rr, gg, bb, aa); // initiate size of arrat Worms = new worm[POP]; // populate worms array for(int i = 0; i < POP; i++){ Worms[i] = new worm((int)random(width), (int)random(height)); } } void loop(){ stepDist = (abs(mouseX - pmouseX) + abs(mouseY - pmouseY))/2 + 15; if(blurCount++ > 4){ blurCount = 0; blur(); } for(int i = 0; i < POP; i++){ Worms[i].update(); Worms[i].updateMem(); Worms[i].draw(); } } void keyPressed(){ if(key == 'e'){ rr = max(0, rr - rgbSpeed); }else if(key == 'r'){ rr = min(255, rr + rgbSpeed); }else if(key == 'f'){ gg = min(255, gg - rgbSpeed); }else if(key == 'g'){ gg = min(255, gg + rgbSpeed); }else if(key == 'v'){ bb = min(255, bb - rgbSpeed); }else if(key == 'b'){ bb = min(255, bb + rgbSpeed); } stroke(rr, gg, bb, aa); } void mousePressed(){ for(int i = 0; i < POP; i++){ Worms[i].spread(); } } class worm{ int x; int y; int px; int py; float fx; float fy; int[] memX = new int[4]; int[] memY = new int[4]; public worm(int xx, int yy){ x = xx; y = yy; fx = (float)xx; fy = (float)yy; memX[0] = x; memX[1] = x; memX[2] = x; memX[3] = x; } void update(){ // memory px = x; py = y; // X fx = ((random(stepDist) - stepDist/2) + mouseX); fx = min(fx, width); fx = max(fx, 0); x = (int)fx; // Y fy = ((random(stepDist) - stepDist/2) + mouseY); fy = min(fy, height); fy = max(fy, 0); y = (int)fy; } // create a spasm in the recent memory :) void spread(){ memX[1] = mouseX + (int)random(-30, 30); memY[1] = mouseY + (int)random(-30, 30); memX[2] = mouseX + (int)random(-50, 50); memY[2] = mouseY + (int)random(-50, 50); memX[3] = mouseX + (int)random(-70, 70); memY[3] = mouseY + (int)random(-70, 70); } void updateMem(){ memX[0] = memX[1]; memX[1] = memX[2]; memX[2] = memX[3]; memX[3] = x; memY[0] = memY[1]; memY[1] = memY[2]; memY[2] = memY[3]; memY[3] = y; } void draw(){ beginShape(LINE_STRIP); curveVertex(memX[0], memY[0]); curveVertex(memX[1], memY[1]); curveVertex(memX[2], memY[2]); curveVertex(memX[3], memY[3]); endShape(); } } // FULL RGB DIFFUSION FILTER // by SEB // www.seb.cc void blur() { int index,R,G,B,left,right,top,bottom; for(int j=0;j0) left=-1; else left=WIDTH-1; if(j==(WIDTH-1)) right=-WIDTH+1; else right=1; if(i>0) top=-WIDTH; else top=(HEIGHT-1)*WIDTH; if(i==(HEIGHT-1)) bottom=-(HEIGHT-1)*WIDTH; else bottom=WIDTH; // Calculate the sum of n neighbors R=(pixels[left+index]>>16) & 255; // left middle R+=(pixels[right+index]>>16) & 255; // right middle R+=(pixels[index]>>16) & 255; // middle middle R+=(pixels[index+top]>>16) & 255; // middle top R+=(pixels[index+bottom]>>16) & 255; // middle bottom R=(R/5); G=(pixels[left+index]>>8) & 255; // left middle G+=(pixels[right+index]>>8) & 255; // right middle G+=(pixels[index]>>8) & 255; // middle middle G+=(pixels[index+top]>>8) & 255; // middle top G+=(pixels[index+bottom]>>8) & 255; // middle bottom G=(G/5); B=pixels[left+index] & 255; // left middle B+=pixels[right+index] & 255; // right middle B+=(pixels[index] & 255); // middle middle B+=pixels[index+top] & 255; // middle top B+=pixels[index+bottom] & 255; // middle bottom B=(B/5); pixels[index]=(R<<16)+(G<<8)+B; } } }