Plastic Pixel Lighting
Sunday, September 21st, 2008I 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:
- 
stage.frameRate = 31;
- 
var canvas:BitmapData = new BitmapData(100,100,true,0xFFFFFFFF);
- 
addChild(new Bitmap(canvas, "auto", true));
- 
scaleX = 4;
- 
scaleY = 4;
- 
- 
addEventListener(Event.ENTER_FRAME, onLoop);
- 
- 
var inc:int = 0;
- 
var cols:Array = new Array();
- 
var num:int = 10000
- 
- 
- 
for (var i:int = 0; i<num; i++){
- 
cols.push(0);
- 
}
- 
- 
Mouse.hide();
- 
- 
function onLoop(evt:Event):void {
- 
inc = 0
- 
for (i = 0; i<100; i++){
- 
for (var j:int = 0; j<100; j++){
- 
var d:Number = (Math.atan2(mouseY - i, mouseX - j) / Math.PI * 180) <<8 ;
- 
if (d> 255){
- 
d = 255-d;
- 
}
- 
// remove this line to see something completely different
- 
d = d% 255;
- 
cols[inc] += ((d) - cols[inc])/32;
- 
- 
canvas.setPixel(j, i, 0xFF000000 + (cols[inc]<<16) + (cols[inc]<<8) + cols[inc])
- 
inc++;
- 
}
- 
}
- 
}
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.

