Node3D
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/evTn
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.filters.BlurFilter;
import com.greensock.*;
import com.greensock.easing.*;
public class Node3D extends Sprite
{
protected const NUM_COPIES:int = 40;
public function Node3D()
{
var W:Number = stage.stageWidth;
var H:Number = stage.stageHeight;
stage.addEventListener( Event.ENTER_FRAME, initEnvironment);
}
public function initEnvironment( event:Event ):void
{
stage.removeEventListener( Event.ENTER_FRAME, initEnvironment);
for (var i:int = 0; i < NUM_COPIES; i++)
{
var s:Sprite = new Sprite();
var m:Matrix = new Matrix();
var randomColor:uint = new uint( 0xffffff*Math.random() );
m.createGradientBox(40, 40, 0, -20, -20);
s.graphics.beginGradientFill(GradientType.RADIAL, [randomColor, randomColor*Math.random()],
[1, 1], [0, 255], m, null, null, 0.6);
s.graphics.drawCircle(0, 0, 6);
s.graphics.endFill();
s.x = (Math.random()-0.5)*200 + 0.5*W;
s.y = (Math.random()-0.5)*200 + 0.5*H;
s.z = -(i-NUM_COPIES/2) * W/NUM_COPIES;
s.filters = [new BlurFilter(0, 0, 3)];
addChild(s);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
protected function onEnterFrame(event:Event):void
{
var focusZ:Number = stage.mouseX - stage.stageWidth/2;
for (var i:int = 0; i < numChildren; i++) {
var s:Sprite = Sprite(getChildAt(i));
var blurFilter:BlurFilter = BlurFilter(s.filters[0]);
var blurAmount:Number = 0.05 * Math.abs(focusZ - s.z);
blurFilter.blurX = blurAmount;
blurFilter.blurY = blurAmount;
s.filters = [blurFilter];
}
}
}
}
}