ActiveBlur
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2JoN
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import com.greensock.*;
import com.greensock.easing.*;
public class Main extends Sprite
{
private const IMAGE_URL:Array = ["http://a0.twimg.com/profile_images/1389298946/me_photo_cold_flash.png"];
private const GRID_SIZE:int = 8;
private var screen:BitmapData;
private var source:BitmapData;
private var frameCount:int = 0;
private var numCols:int,numRows:int;
// The Main constructor simply calles initialize() function.
public function Main():void
{
if (stage != null)
{ initialize(null); }
else
{ this.addEventListener(Event.ADDED_TO_STAGE, initialize); }
TweenMax.to(this, 2, {blurFilter:{blurX:20, blurY:20, quality:2}, ease:Cubic.easeInOut});
}
private function loadImage():void
{
var message:TextField = new TextField();
message.autoSize = TextFieldAutoSize.LEFT;
message.textColor = 0xffffff;
message.background = false;
message.text = "LOADING IMAGE...";
message.x = (stage.stageWidth-message.width)/2;
message.y = (stage.stageHeight-message.height)/2;
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(
Event.COMPLETE,
function (e:Event):void {
source.draw(ldr);
ldr.unload();
message.text = "";
}
);
this.addChild(message);
ldr.load(new URLRequest( IMAGE_URL[ Math.floor(Math.random()*IMAGE_URL.length) ] ), context );
}
private function setGrid(h:int,v:int,c:uint):void {
if ( ( h < 0 )||( h >= stage.stageWidth/GRID_SIZE ) ) return;
if ( ( v < 0 )||( v >= stage.stageHeight/GRID_SIZE ) ) return;
screen.fillRect(
new Rectangle(
h*GRID_SIZE+1,
v*GRID_SIZE+1,
GRID_SIZE-1,
GRID_SIZE-1
),
c
);
}
private function atEveryFrame(e:Event):void
{
var i:int,j:int;
for ( i = 0 ; i < numCols ; ++i )
for ( j = 0 ; j < numRows ; ++j ) {
var c:uint = source.getPixel(
i*GRID_SIZE+Math.floor(Math.random()*GRID_SIZE),
j*GRID_SIZE+Math.floor(Math.random()*GRID_SIZE)
);
setGrid(i,j,c);
}
}
private function redrawGrid():void {
var GRID_COLOR:uint = 0x006600;
var col:int;
var row:int;
col = 0;
while ( col < stage.stageWidth ) {
for ( row = 0 ; row < stage.stageHeight ; ++row )
screen.setPixel(col,row,GRID_COLOR);
col += GRID_SIZE;
}
row = 0;
while ( row < stage.stageHeight ) {
for ( col = 0 ; col < stage.stageWidth ; ++col )
screen.setPixel(col,row,GRID_COLOR);
row += GRID_SIZE;
}
}
private function initialize(e:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, initialize);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
screen = new BitmapData(stage.stageWidth,stage.stageHeight,false,0);
source = new BitmapData(stage.stageWidth,stage.stageHeight,false,0);
this.addChild(new Bitmap(screen));
loadImage();
frameCount = 0;
numCols = Math.floor(stage.stageWidth/GRID_SIZE);
numRows = Math.floor(stage.stageHeight/GRID_SIZE);
stage.addEventListener(Event.ENTER_FRAME, atEveryFrame);
}
} // end of class Main
}
import flash.events.Event; // end of package
// NOTES
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
/*
import net.hires.debug.Stats;
var stats:Stats = new Stats();
this.addChild(stats)Event
public function EffectContainer(event:Event):void
{
TweenMax.to(this, 2, {blurFilter:{blurX:20, blurY:20, quality:2}, ease:Cubic.easeInOut});
}
*/