ThePirate
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jQYB
*/
// forked from bradsedito's forked from: Happy New Year
// forked from buddylee101's Happy New Year
package
{
import flash.display.*;
import flash.events.*;
import flash.filters.BlurFilter;
import flash.system.LoaderContext;
import flash.geom.*;
import flash.net.URLRequest;
import caurina.transitions.Tweener;
import caurina.transitions.properties.ColorShortcuts;
[SWF(backgroundColor = "#232323", frameRate = "100", width = "465", height = "465")]
public class FlashTest extends MovieClip
{
private const IMAGE_PATH:String = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/211638_100000254064606_829109_n.jpg";
private const POINT_MARGIN:Number = 4;
private const MAX_SPEED:Number = 0.08;
private var _canvas:BitmapData;
private var _cBm:Bitmap;
private var _glow:BitmapData;
private var _gBm:Bitmap;
private var _glowMtx:Matrix;
private var _color:uint = 0;
private var _text:Bitmap;
private var _sPoints:Array = [];
private var _ePoints:Array = [];
private var _tPoints:Array = [];
private var _wRate:Number;
private var _hRate:Number;
public function FlashTest()
{
_init();
Wonderfl.capture_delay(3);
}
private function _init():void
{
ColorShortcuts.init();
_canvas = new BitmapData(465, 465, true, 0x0);
_cBm = new Bitmap(_canvas);
_cBm.smoothing = true;
_cBm.alpha = 0;
addChild(_cBm);
_glow = new BitmapData(_canvas.width / 10, _canvas.height / 10, false, 0x0);
_gBm = new Bitmap(_glow, PixelSnapping.NEVER, true);
_gBm.scaleX = _gBm.scaleY = 10;
_gBm.blendMode = BlendMode.ADD;
_gBm.alpha = 0;
addChild(_gBm);
_glowMtx = new Matrix(0.10, 0, 0, 0.10);
_loadImage();
}
private function _loadImage():void
{
var _loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onComplete, false, 0, true);
_loader.load(new URLRequest(IMAGE_PATH), new LoaderContext(true));
}
private function _onComplete(e:Event):void
{
var _loader:Loader = e.target.loader as Loader;
var _bmd:BitmapData = Bitmap(_loader.content).bitmapData;
for (var i:int = 0; i < _bmd.width; i += POINT_MARGIN) {
for (var j:int = 0; j < _bmd.height; j += POINT_MARGIN) {
_pushPixel(_bmd, i, j);
}
}
_setPixelImage();
var _textBmd:BitmapData = _bmd.clone();
_text = new Bitmap(_textBmd);
_text.smoothing = true;
_text.x = 5;
_text.y = 150;
_text.alpha = 0;
addChildAt(_text, 0);
trace(_text.width, _text.height);
stage.addEventListener(MouseEvent.CLICK, _restart, false, 0, true);
}
private function _restart(e:MouseEvent):void
{
Tweener.removeAllTweens();
_sPoints = [];
removeEventListener(Event.ENTER_FRAME, _update);
removeEventListener(Event.ENTER_FRAME, _checkLength);
_cBm.alpha = 1;
_gBm.alpha = 1;
_text.alpha = 0;
_canvas.fillRect(_canvas.rect, 0x0);
_glow.fillRect(_canvas.rect, 0x0);
_setPixelImage();
addEventListener(Event.ENTER_FRAME, _update, false, 0, true);
addEventListener(Event.ENTER_FRAME, _checkLength, false, 0, true);
}
private function _pushPixel(bmd:BitmapData, x:Number, y:Number):void
{
var _p:Particle = new Particle();
_p._x = x + 5;
_p._y = y + 150;
_p._c = bmd.getPixel32(x, y);
if (_p._c != 0x0) {
_ePoints.push(_p);
}
}
private function _setPixelImage():void
{
var _l:int = _ePoints.length;
for (var i:int = 0; i < _l; i++)
{
var _p:Particle = new Particle();
_p._x = Math.random() * 465;
_p._y = Math.random() * 465;
_canvas.setPixel32(_p._x, _p._y, _ePoints[i]._c);
_sPoints.push(_p);
}
}
private function _update(e:Event):void
{
_canvas.lock();
_glow.fillRect(_canvas.rect, 0x0);
_canvas.applyFilter(_canvas, _canvas.rect, new Point(), new BlurFilter(5, 5));
_tPoints = [];
_tPoints = _ePoints.slice(0);
var _i:int = _tPoints.length;
while (_i--) {
var _s:Particle = _sPoints[_i];
var _e:Particle = _ePoints[_i];
_s._speed += _s._speedChange;
if (_s._speed >= MAX_SPEED) {
_s._speed = MAX_SPEED;
}
_s._x += (_e._x - _s._x) * _s._speed * (Math.random() * 2);
_s._y += (_e._y - _s._y) * _s._speed * (Math.random() * 2);
if (Math.abs(_e._x - _s._x) < 1 && Math.abs(_e._y - _s._y) < 1)
{
_s._x = _e._x;
_s._y = _e._y;
_tPoints.splice(_i, 1);
}
_canvas.setPixel32(_s._x, _s._y, _e._c);
}
_canvas.unlock();
_glow.draw(_canvas, _glowMtx);
if (_tPoints.length <= 0) {
removeEventListener(Event.ENTER_FRAME, _update);
}
}
private function _checkLength(e:Event):void
{
if (_tPoints.length <= 500) {
removeEventListener(Event.ENTER_FRAME, _checkLength);
Tweener.addTween(_text, { alpha:1, time:2.0, transition:"Linear" } );
Tweener.addTween(_cBm, { alpha:0, time:2.0, transition:"Linear" } );
Tweener.addTween(_gBm, { alpha:0, time:2.0, transition:"Linear" } );
}
}
}
}
class Particle
{
public var _x:Number;
public var _y:Number;
public var _speed:Number = 0;
public var _speedChange:Number = Math.random() * 0.001 + 0.0001;
public var _c:uint;
public function Particle() { }
}