Plastic Pixel Lighting

September 21st, 2008

I started working on some fluid dynamics today and got sidetracked .... somehow it turned into this:



Click above image to see flash version

Here's the code:

Actionscript:
  1. stage.frameRate = 31;
  2. var canvas:BitmapData = new BitmapData(100,100,true,0xFFFFFFFF);
  3. addChild(new Bitmap(canvas, "auto", true));
  4. scaleX = 4;
  5. scaleY = 4;
  6.  
  7. addEventListener(Event.ENTER_FRAME, onLoop);
  8.  
  9. var inc:int = 0;
  10. var cols:Array = new Array();
  11. var num:int = 10000
  12.  
  13.  
  14. for (var i:int = 0; i<num; i++){
  15.     cols.push(0);
  16. }
  17.  
  18. Mouse.hide();
  19.  
  20. function onLoop(evt:Event):void {
  21.     inc = 0
  22.     for (i = 0; i<100; i++){
  23.         for (var j:int = 0; j<100; j++){
  24.             var d:Number(Math.atan2(mouseY - i, mouseX - j) / Math.PI * 180) <<8  ;
  25.             if (d> 255){
  26.                 d = 255-d;
  27.             }
  28.                        // remove this line to see something completely different
  29.             d = d% 255;
  30.             cols[inc] += ((d) - cols[inc])/32;
  31.            
  32.             canvas.setPixel(j, i, 0xFF000000 + (cols[inc]<<16) + (cols[inc]<<8) + cols[inc]) 
  33.             inc++;
  34.         }
  35.     }
  36. }

try removing line 29....

I've actually tried to do this kind of effect before ... it really has a subtle feel of lighting - like pushing on a thin layer of plastic. I plan on taking this a step or two further.

One Response to “Plastic Pixel Lighting”

  1. LOST'овчанин Says:

    Hi Zevan!!! It’s cool!!! Thank you!

Leave a Reply