Filter
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import org.libspark.thread.EnterFrameThreadExecutor;
import org.libspark.thread.Thread;
[SWF(backgroundColor="#000000")]
public class Filter extends Sprite
{
public function Filter()
{
super();
Thread.initialize(new EnterFrameThreadExecutor());
new MainThread(this).start();
addEventListener(Event.ADDED_TO_STAGE, addToStageHandler);
}
private function addToStageHandler(event:Event):void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
}
}
import org.libspark.thread.Thread;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
class MainThread extends Thread
{
private static const BASE_URL:String = 'http://seagirl.jp/assets/images/';
private static const WIDTH:int = 700;
private static const HEIGHT:int = 700;
private static const VELOCITY:int = 1;
private static const DEGREE:int = 310;
private static const RANGE:int = 1200;
public function MainThread(document:Sprite)
{
this.document = document;
}
private var document:Sprite;
private var target:Bitmap;
private var velocity:Number;
private var angle:Number;
private var assets:Array = [];
private var assetsLoader:Executor;
private var filters:Array;
override protected function run():void
{
next(loadAssets);
}
private function loadAssets():void
{
assetsLoader = new ParallelExecutor();
assetsLoader.addThread(new LoaderThread(new URLRequest(BASE_URL + '6.jpg'), new LoaderContext(true)));
assetsLoader.addThread(new LoaderThread(new URLRequest(BASE_URL + '2.jpg'), new LoaderContext(true)));
assetsLoader.start();
assetsLoader.join();
next(assetsDidLoaded);
}
private function assetsDidLoaded():void
{
for (var i:int = 0; i < assetsLoader.numThreads; i++)
{
assets.push(LoaderThread(assetsLoader.getThreadAt(i)).loader.content);
}
next(show);
}
private function show():void
{
velocity = VELOCITY / 1000;
angle = Math.PI / 180 * DEGREE;
target = Bitmap(assets[0]);
target.alpha = 0;
target.x = (document.stage.stageWidth - target.width) / 2;
target.y = (document.stage.stageHeight - target.height) / 2;
document.addChild(target);
document.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler(event:Event):void
{
var amplitude:Number = Math.sin(angle);
var scale:Number = amplitude * 1200;
if (amplitude >= -0.7)
{
if (document.hasEventListener(Event.ENTER_FRAME))
document.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
target.filters =
[
new GradientRadialFilter(scale, scale, WIDTH, HEIGHT, Bitmap(assets[1]).bitmapData).create()
];
target.alpha = 1;
target.width = Math.abs(Math.cos(angle)) * WIDTH;
target.height = Math.abs(Math.cos(angle)) * HEIGHT;
target.x = (document.stage.stageWidth - target.width) / 2;
target.y = (document.stage.stageHeight - target.height) / 2;
angle += velocity;
}
}
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.GradientType;
import flash.display.Sprite;
import flash.filters.BitmapFilter;
import flash.filters.DisplacementMapFilter;
import flash.filters.DisplacementMapFilterMode;
import flash.geom.Matrix;
import flash.geom.Point;
import org.libspark.thread.utils.Executor;
import org.libspark.thread.utils.ParallelExecutor;
import org.libspark.thread.threads.display.LoaderThread;
import flash.net.URLRequest;
import flash.system.LoaderContext;
class GradientRadialFilter
{
public function GradientRadialFilter(scaleX:Number = 0.0,
scaleY:Number = 0.0,
width:int = 0,
height:int = 0,
mapBitmap:BitmapData = null,
mapPoint:Point = null,
componentX:uint = 4,
componentY:uint = 1,
mode:String = "color",
color:uint = 0,
alpha:Number = 0.0
)
{
if (mapBitmap == null)
mapBitmap = createMapBitmap(width, height, [100, 255]);
bitmapFilter = new DisplacementMapFilter(mapBitmap,
mapPoint,
componentX,
componentY,
scaleX,
scaleY,
mode,
color,
alpha
);
}
private var bitmapFilter:BitmapFilter;
public function create():BitmapFilter
{
return bitmapFilter;
}
private function createMapBitmap(width:int, height:int, ratio:Array):BitmapData
{
var matrix:Matrix = new Matrix();
matrix.createGradientBox(width, height, 0, 0, 0);
var map:Sprite = new Sprite();
map.graphics.beginGradientFill(GradientType.RADIAL, [0xff0000, 0x0000ff], [1, 1], ratio, matrix);
map.graphics.drawRect(0, 0, width, height);
map.graphics.endFill();
var mapBitmap:BitmapData = new BitmapData(width, height, true, 0);
mapBitmap.draw(map);
return mapBitmap;
}
}