// Flux 02 (2005. 1. 10.) // by SeungJoon Choi // erucipe@hanmail.net // // original diffuse filter from http://www.sebchevrel.com // http://processing.org VCell[] vcells; Particle[] ptcls; int nw, nh, n_ptcls; float csize; //float[] clearZ; int kR, kG, kB; int kR2, kG2, kB2; void setup() { size(400, 300); background(random(255), random(255), random(255)); rectMode(CENTER_DIAMETER); //clearZ = new float[width*height]; //System.arraycopy(clearZ, 0, g.zbuffer, 0, g.zbuffer.length); g.depthTest = false; noStroke(); nw = 8; nh = 6; csize = width / nw; vcells = new VCell[nw * nh]; for(int y = 0; y < nh; y++) for(int x = 0; x < nw; x++) { int i = y * nw + x; vcells[i] = new VCell(x * csize - (nw - 1) * csize * 0.5, y * csize - (nh - 1) * csize * 0.5, csize); } kR = (int)random(255); kG = (int)random(255); kB = (int)random(255); kR2 = (int)random(255); kG2 = (int)random(255); kB2 = (int)random(255); color pcolor = color(kR, kG, kB); n_ptcls = 750; ptcls = new Particle[n_ptcls]; for(int i = 0; i < n_ptcls; i++) { ptcls[i] = new Particle((1-random(2))*200, (1-random(2))*150, 0, pcolor); } //fill(255, 255, 255); //ellipse(0, 0, width, height); } float itr = 1; int okR, okG, okB; void loop() { push(); beginCamera(); perspective(60, (float)width / (float)height, 1, 1000); //lookat(0, 0, 261, 0, 0, 0, 0, 1, 0); lookat(0, 0, 261 - 10*(1+sin(millis()*0.001)), 0, 0, 0, 0, 1, 0); endCamera(); pop(); if(mousePressed) { background(255); stroke(kR, kG, kB); drawVCells(); } drawPtcls(); drawPtcls(); /* push(); rotateY(PI*millis()*0.00001); drawPtcls(); pop(); */ if(random(1) > 0.2) { blur(); } if(itr < 1) { itr += 0.005; } else { okR = kR; okG = kG; okB = kB; kR = 64 + (int)random(191); kG = 64 + (int)random(191); kB = 64 + (int)random(191); kR2 = (int)random(255); kG2 = (int)random(255); kB2 = (int)random(255); itr = 0; } } int Red(int c) { return (c & 0xff0000) >> 16; } int Green(int c) { return (c & 0x00ff00) >> 8; } int Blue(int c) { return c & 0x0000ff; } void blur() { int index,left,right,top,bottom; int sumr, sumg, sumb; 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 sumr=Red(pixels[left+index]); // left middle sumg=Green(pixels[left+index]); sumb=Blue(pixels[left+index]); //sum+=pixels[left+top+index] & 255; // left top //sum+=pixels[left+bottom+index] & 255; // left bottom sumr+=Red(pixels[right+index]); // right middle sumg+=Green(pixels[right+index]); sumb+=Blue(pixels[right+index]); //sum+=pixels[right+top+index] & 255; // right top //sum+=pixels[right+bottom+index] & 255; // right bottom sumr+=Red(pixels[index]); // middle middle sumg+=Green(pixels[index]); sumb+=Blue(pixels[index]); sumr+=Red(pixels[index+top]); // middle top sumg+=Green(pixels[index+top]); sumb+=Blue(pixels[index+top]); sumr+=Red(pixels[index+bottom]); // middle bottom sumg+=Green(pixels[index+bottom]); sumb+=Blue(pixels[index+bottom]); sumr=(int)((float)sumr/4.99); sumg=(int)((float)sumg/4.99); sumb=(int)((float)sumb/4.99); pixels[index]=(sumr<<16)+(sumg<<8)+sumb; } } } void mouseReleased() { //System.arraycopy(clearZ, 0, g.zbuffer, 0, g.zbuffer.length); background(random(255), random(255), random(255)); kR = (int)random(255); kG = (int)random(255); kB = (int)random(255); for(int i = 0; i < n_ptcls; i++) { ptcls[i].kr = kR + (int)((1-random(2))*64); ptcls[i].kg = kG + (int)((1-random(2))*64); ptcls[i].kb = kB + (int)((1-random(2))*64); } } void drawVCells() { for(int y = 0; y < nh; y++) for(int x = 0; x < nw; x++) { int i = y * nw + x; vcells[i].Draw(); } } void drawPtcls() { for(int i = 0; i < n_ptcls; i++) { ptcls[i].Move(); ptcls[i].Draw(); } } class VCell { public VCell(float _x, float _y, float _size) { x = _x; y = _y; size = _size; arrow = new Arrow(x, y, size, (1-random(2))*PI); } public void Draw() { push(); translate(x, y, 0); rect(0, 0, size, size); if(mousePressed) takeAngle(); arrow.Draw(); pop(); } private void takeAngle() { if(mouseY > screenY(0, -size*0.5, 0) && mouseY < screenY(0, size*0.5, 0)) if(mouseX > screenX(-size*0.5, 0, 0) && mouseX < screenX(size*0.5, 0, 0)) { arrow.angle = atan2(mouseY - pmouseY, mouseX - pmouseX); //arrow.angle = atan2(mouseY - screenY(0, 0, 0), mouseX - screenX(0, 0, 0)) + PI*0.5; } } public float x, y, size; Arrow arrow; } class Arrow { public Arrow(float _ox, float _oy, float _size, float _angle) { ox = _ox; oy = _oy; radius = _size * 0.5 * 0.75; angle = _angle; } public void Draw() { push(); rotateZ(angle + PI*0.5); beginShape(POLYGON); vertex(0, -radius, 0); vertex(-radius*0.3, -radius + radius*0.4, 0); vertex(-radius*0.1, -radius + radius*0.4, 0); vertex(-radius*0.1, radius, 0); vertex(radius*0.1, radius, 0); vertex(radius*0.1, -radius + radius*0.4, 0); vertex(radius*0.3, -radius + radius*0.4, 0); vertex(0, -radius, 0); endShape(); //line(0, -radius, 0, radius); pop(); } public float ox, oy, radius, angle; } class Particle { public Particle(float _x, float _y, float _z, color pcolor) { oldx = _x; oldy = _y; oldz = _z; x = _x; y = _y; z = _z; rw = nw * csize * 0.5; rh = nh * csize * 0.5; ax = 100; ay = 100; vx = 0; vy = 0; dt = 0.012; kr = (int)red(pcolor); kg = (int)green(pcolor); kb = (int)blue(pcolor); kr += (int)((1-random(2))*64); kg += (int)((1-random(2))*64); kb += (int)((1-random(2))*64); } public void Move() { oldx = x; oldy = y; oldz = z; int ix = (int)((x + rw) / csize); int iy = (int)((y + rh) / csize); if(ix > nw-1) ix = 0; if(iy > nh-1) iy = 0; if(ix < 0) ix = nw - 1; if(iy < 0) iy = nh - 1; VCell vcell = vcells[iy * nw + ix]; vx += ax*cos(vcell.arrow.angle)*dt; vy += ay*sin(vcell.arrow.angle)*dt; x += vx*dt; y += vy*dt; vx *= 0.99; vy *= 0.99; if(x < -rw) {x = rw; oldx = rw;} if(x > rw) {x = -rw; oldx = -rw;} if(y < -rh) {y = rh; oldy = rh;} if(y > rh) {y = -rh; oldy = -rh;} } public void Draw() { if(itr < 1) { } else { if(random(1) > 0.5) { kr = kR + (int)((1-random(2))*64); kg = kB + (int)((1-random(2))*64); kb = kB + (int)((1-random(2))*64); } else { kr = kR2 + (int)((1-random(2))*32); kg = kB2 + (int)((1-random(2))*32); kb = kB2 + (int)((1-random(2))*32); } okr = okR + (int)((1-random(2))*64); okg = okB + (int)((1-random(2))*64); okb = okB + (int)((1-random(2))*64); } //stroke(kr, kg, kb, 127); //line(oldx, oldy, oldz, x, y, z); push(); translate(x, y, 0); noStroke(); //fill(kr, kg, kb, 32); fill((1-itr)*okr + itr*kr, (1-itr)*okg + itr*kg, (1-itr)*okb + itr*kb, 32); rect(0, 0, 1, 1); pop(); if(mousePressed) { push(); translate(x, y, 0); noFill(); stroke(kR, kG, kB, 255); rect(0, 0, 2, 2); pop(); } } float oldx, oldy, oldz; float x, y, z, rw, rh; float vx, vy, ax, ay, dt; int kr, kg, kb; int okr, okg, okb; }