// EYE by Zevan Rosser int WIDTH = 400; int HEIGHT = 300; int SIZE= WIDTH*HEIGHT; //--------------------- // eye setup //--------------------- int centerX=200; int centerY=150; int eyeState = 1; int eyeFxTimer = 0; // iris brush: int irisRadius = 100; int ibNum = 1000; IrisBrush[] ib = new IrisBrush[ibNum]; // eye shadows: BGraphics eyeShadows = new BGraphics(400, 400); BImage sss = new BImage(400,400); // veins: int vnNum = 10; VeinBrush[] vn = new VeinBrush[vnNum]; void setup(){ // size(400,300); background(0xffffff); noStroke(); smooth(); ellipseMode(CENTER_RADIUS); // iris brush instances for (int i = 0; i< ibNum; i++){ ib[i]= new IrisBrush(i); } createEyeShadows(); //vein brush instances for (int i = 0; i< vnNum; i++){ vn[i]= new VeinBrush(); } } void loop(){ if (eyeState == 1){ // draw iris for (int i = 0; i< ibNum; i++){ ib[i].action(); } // end state1 } if (eyeState == 2){ // set irisBrush instances to null for (int i = 0; i< ibNum; i++){ ib[i]=null; } // apply eye shadows to iris if (eyeFxTimer==0){ // setup ellipseMode for veins for (int i = 0; i < SIZE; i++){ pixels[i]=blendC(pixels[i],0,eyeShadows.pixels[i]&255); } // set BGraphics eyeShadows to null eyeShadows = null; } eyeFxTimer++; // blur iris if (eyeFxTimer<2){ blur(); } // overexpose iris if (eyeFxTimer>3 && eyeFxTimer<7){ for(int i =0; i9 && eyeFxTimer<48){ for (int i = 0; i < SIZE; i++){ pixels[i]=blendC(sss.pixels[i],pixels[i],10); } } if (eyeFxTimer>48){ for (int i = 0; i< vnNum; i++){ vn[i].action(); } } // end state 2 } // } //-------------------------------------------------------------------------- // Iris Brush class //-------------------------------------------------------------------------- class IrisBrush { float posX; float posY; float destX; float destY; int idNum; // int currentColor; int colorDest; int colorBlend; int colorTimer = 0; boolean colorDone=false; int[] colors={0x315160,0x588598,0x628486,0x62899A,0x305162,0x688887,0x678698}; IrisBrush(int num){ posX = centerX + irisRadius * sin(num*ibNum); posY = centerY + irisRadius * cos(num*ibNum); idNum = num; destX=centerX; destY=centerY; colorDest = colors[(int)(random(colors.length))]; currentColor=colors[(int)(random(colors.length))]; } void action(){ colorTimer ++; if (colorTimer == 130){ eyeState = 2; }else{ alph=30; col = 0x000000; posX += (destX -posX)/random(2,130); posY += (destY -posY)/random(2,130); wuPixel(posX,posY); alph=(int)(random(120,121)); colorBlend+=random(2,20); if ((int)(random(100))==1){ colorDest=colors[(int)(random(colors.length))]; } if (colorBlend<255){ col=blendC(currentColor,colorDest,colorBlend); posX += (destX -posX)/random(111,210); posY += (destY -posY)/random(111,210); wuPixel(posX,posY); wuPixel(posX+2,posY); wuPixel(posX+2,posY+2); wuPixel(posX,posY+2); }else if (colorDone==false){ posX = centerX + irisRadius * sin(idNum*ibNum); posY = centerY + irisRadius * cos(idNum*ibNum); colorDone = true; } } } } //-------------------------------------------------------------------------- // VeinBrush class //-------------------------------------------------------------------------- class VeinBrush{ float posX; float posY; float tdestX; float tdestY; float destX; float destY; float bx,by; float st; float randRot; float rad,radDest; float _alpha = 0; float veinTimer; VeinBrush(){ /* randRot = random(PI); st = (random)*(PI/180); if ((int)(random(2))==1){ st *= -1; randRot = random(-PI); }*/ st = random(TWO_PI); destX = centerX + (irisRadius*(1+random(2))) * sin(st); destY = centerY + (irisRadius*(1+random(2))) * cos(st); float q = random(TWO_PI); posX= centerX + (irisRadius+random(10)) * sin(st); posY= centerY + (irisRadius+random(10))* cos(st); tdestX = posX; tdestY = posY; rad = random(1.5); radDest = rad; } void action(){ if (veinTimer<350){ veinTimer++; posX -= bx; bx = ((posX - tdestX)/37+bx)/1.12; posY -= by; by = ((posY - tdestY)/37+by)/1.12; if ((int)(random(10))==1){ tdestX += random(6)-3; tdestX+=(destX - tdestX)/32; tdestY += random(6)-3; tdestY+=(destY - tdestY)/36; } if ((int)(random(10)) == 1) { radDest = random(2); } rad +=(radDest-rad)/12; _alpha +=(35 - _alpha)/112; ellipseMode(CORNER); fill(255,(int)(random(100)),0,_alpha); ellipse(posX,posY,rad,rad); //fill(255,255,255,100); //ellipse(posX,posY-2,rad,rad); if ((int)(random(150))==1){ ellipseMode(CENTER_RADIUS); fill(255,55,0,1); ellipse(posX,posY,20,20); } } } } void createEyeShadows(){ eyeShadows.noStroke(); eyeShadows.smooth(); eyeShadows.fill(0); eyeShadows.ellipseMode(CENTER_RADIUS); eyeShadows.background(0xFFFFFF); for (int i = 0; i<20; i++){ eyeShadows.fill(i*10,i*10,i*10,30); eyeShadows.ellipse(centerX,centerY,100-i*2,100-i*2); } for (int i = 0; i<40; i++){ eyeShadows.fill(255,255,255,155-(i*4)); eyeShadows.ellipse(centerX-10+(i/10),centerY-10+(i/10),i*2.5,i*2.5); } } //----------------------------------------- // graphics methods & variables //----------------------------------------- int MR = 0x00ff0000; int MG = 0x0000ff00; int MB = 0x000000ff; int MRB= 0x00ff00ff; // int col=0x000000; int alph=55; //-------------------------------------------------------------------------- // wupixel( x, y, color ) // sets an anti-ailiased pixel (4 pixels) //-------------------------------------------------------------------------- void wuPixel(float ax, float ay) { // original method by Glen Murphy from bodytag.org int x = (int)ax; int y = (int)ay; //if(x <= 0 || x >= width-1 || y <= 0 || y >= height-1) return ; float fx = ax - x; float fy = ay - y; float nfx=1-fx; float nfy=1-fy; int loc=x+y*width; int loc2=loc+width; int loc4=loc2+1; int loc3=loc+1; pixels[loc] = blendC(col, pixels[loc], (int)((nfx) *(nfy)*alph)); pixels[loc3] = blendC(col, pixels[loc3], (int)((fx) *(nfy)*alph)); pixels[loc2] = blendC(col, pixels[loc2], (int)((nfx) *(fy) *alph)); pixels[loc4] = blendC(col, pixels[loc4], (int)((fx) *(fy) *alph)); } //-------------------------------------------------------------------------- // blendC(colorA, colorB, mix amount) // blends 2 colors //-------------------------------------------------------------------------- int blendC(int color1, int color2, int amount) { int m1=(color2 & MRB); int m2=(color2 & MG); return (((amount * ((color1 & MRB) - m1) >> 8) + m1) & MRB) | ((amount * ((color1 & MG) - m2) >> 8) + m2) & MG; } //-------------------------------------------------------------------------- // brightCon(brigntness, contrast, color) // brightness and contrast filter //-------------------------------------------------------------------------- int brightCon(int amount, float con, int mcol){ int r = check((((mcol>>16)&255)+amount)*con); int g = check((((mcol>>8)&255)+amount)*con); int b = check((((mcol)&255)+amount)*con); return (r<<16)+(g<<8)+b; } int colorBurn(int a, int b){ int r = check(255 - ( 255 * ( 255 - ((a>>16)&255) ) / (((b>>16)&255)+1) )); int g = check(255 - ( 255 * ( 255 - ((a>>8)&255) ) / (((b>>8)&255)+1) )); int bb = check(255 - ( 255 * ( 255 - ((a)&255) ) / (((b)&255)+1) )); return (r<<16)+(g<<8)+bb; } //color = 255 - ( 255 * ( 255 - bottom ) / top ) int check (float mcol){ if (mcol>255){ mcol = 255; } if (mcol<0){ mcol = 0; } return (int)(mcol); } //-------------------------------------------------------------------------- // blur (method 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; } } }