forked from: LiquidFx
matrixを使ってみた
/**
* Copyright m_607_m ( http://wonderfl.net/user/m_607_m )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/tPEH
*/
// forked from k3lab's LiquidFx
// matrixを使ってみた
package {
import flash.geom.Matrix;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.events.MouseEvent;
[SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="60")]
public class LiquidFx extends Sprite {
private var main:Sprite;
private var sub:Sprite;
//
private var w:int = 480;
private var h:int = 480;
//
private var mainmask:Sprite;
private var submask:Sprite;
//
private var count:Number=0
private var speed:Number=4;
//
private var matrix:Matrix;
private var original:BitmapData;
public function LiquidFx() {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loader.load(new URLRequest('http://www.k3lab.com/wonderfl/test.jpg'), new LoaderContext(true));
}
private function onImageLoaded(e:Event):void {
var loader:Loader = Loader(LoaderInfo(e.target).loader);
original = Bitmap(loader.content).bitmapData;
//表示用スプライト
main = addChild(new Sprite()) as Sprite;
//main.graphics.beginBitmapFill(original, null, false)
//main.graphics.drawRect(0, 0, w, h);
//main.graphics.endFill();
//エフェクト用スプライト
sub = addChildAt(new Sprite(),0) as Sprite;
//sub.graphics.beginBitmapFill(original, null, false)
//sub.graphics.drawRect(0, 0, w, h);
//sub.graphics.endFill();
sub.scaleX=w
//各マスクセット
//mainmask = addChild(new Sprite()) as Sprite;
//submask = addChild(new Sprite()) as Sprite;
//main.mask = mainmask
//sub.mask = submask
//
matrix = new Matrix();
stage.addEventListener(MouseEvent.MOUSE_DOWN, _down)
addEventListener(Event.ENTER_FRAME,update)
}
private function _down(e:Event):void {
count=0
}
private function update(e:Event):void {
count +=speed
matrix.tx = -count;
sub.graphics.clear();
sub.graphics.beginBitmapFill(original, matrix, false);
sub.graphics.drawRect(0, 0, 1, h);
sub.graphics.endFill();
main.graphics.clear();
main.graphics.beginBitmapFill(original);
main.graphics.drawRect(0, 0, count, h);
main.graphics.endFill();
/*sub.x = (0 - count) *sub.scaleX
submask.graphics.clear();
submask.graphics.beginFill(0x0);
submask.graphics.moveTo(count, 0)
submask.graphics.lineTo(w, 0)
submask.graphics.lineTo(w, h)
submask.graphics.lineTo(count, h)
submask.graphics.lineTo(count, 0)
submask.graphics.endFill()
mainmask.graphics.clear();
mainmask.graphics.beginFill(0);
mainmask.graphics.moveTo(0, 0)
mainmask.graphics.lineTo(count, 0)
mainmask.graphics.lineTo(count, h)
mainmask.graphics.lineTo(0, h)
mainmask.graphics.lineTo(0, 0)
mainmask.graphics.endFill()*/
}
}
}