ゆらゆら気分(DisplacementMapFilter Drunk Effect)
Drunk Effectの簡易版。
画像にDisplacementMapFilterをかけてゆらゆらしてるだけです。
マウスダウンでゆらゆらが大きくなります。
/**
* Copyright mousepancyo ( http://wonderfl.net/user/mousepancyo )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/b52z
*/
/*
Drunk Effectの簡易版。
画像にDisplacementMapFilterをかけてゆらゆらしてるだけです。
マウスダウンでゆらゆらが大きくなります。
*/
package {
import flash.display.Sprite;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.filters.DisplacementMapFilter;
import flash.net.URLRequest;
import flash.system.Security;
[SWF(width = 465,height = 465,backgroundColor = 0,frameRate = 30)]
public class Main extends Sprite {
private const DISTORTION:int = 16;
private const W:int = 465;
private const H:int = 465;
private var _loader:Loader;
private var _canvas:BitmapData;
private var _bm:Bitmap;
private var _mapBmd:BitmapData;
private var _perlinoffset:Array = [new Point()];
private var _randomSeed:int = Math.random() * 0xFF;
private var _isClicked:Boolean;
private var _distScale:int;
public function Main() {
Security.loadPolicyFile("http://www.digifie.jp/crossdomain.xml");
loadImage("http://www.digifie.jp/files/test100726.jpg");
}
private function loadImage(url:String):void {
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
_loader.load(new URLRequest(url));
}
private function onLoaded(e:Event):void {
setUp();
addEventListener(Event.ENTER_FRAME, draw);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
}
private function setUp():void {
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaded);
_canvas = new BitmapData(_loader.width,_loader.height,false,0);
_canvas.draw(_loader);
addChild(_bm = new Bitmap(_canvas,"auto",true)) as Bitmap;
_bm.scaleX = _bm.scaleY = 1.2;
_bm.x = _bm.y = - W * .2 / 2;
_mapBmd = new BitmapData(W,H,false,0);
_distScale = DISTORTION;
}
private function draw(e:Event):void {
_mapBmd.perlinNoise(int(W / 3), int(H / 3), 1, _randomSeed, false, true, 1, true, _perlinoffset);
var dmf:DisplacementMapFilter = new DisplacementMapFilter(_mapBmd,new Point(0,0),1,1,_distScale,_distScale);
_perlinoffset[0].x += Math.random() * 10 + 10;
_perlinoffset[0].y += Math.random() * 10 + 10;
_canvas.draw(_loader);
_canvas.applyFilter(_canvas, _canvas.rect, new Point(), dmf);
}
private function onDown(e:MouseEvent):void {
_distScale = 160;
addEventListener(Event.ENTER_FRAME, scaleChange);
}
private function scaleChange(e:Event):void {
if (_distScale > 16) {
_distScale -= _distScale * .05;
}
else {
_distScale = DISTORTION;
removeEventListener(Event.ENTER_FRAME, scaleChange);
}
}
}
}