forked from: Baby
funnelインポート
// forked from hiro_rec's Baby
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BitmapFilterQuality;
import flash.filters.BlurFilter;
import flash.filters.DisplacementMapFilter;
import flash.geom.Point;
import flash.net.URLRequest;
import flash.system.Security;
import funnel.*;
//funnelインポート
public class Main extends Sprite
{
private static const LEVEL:uint = 1;
private static const BLUR:BlurFilter = new BlurFilter(10, 10, BitmapFilterQuality.LOW);
private var container:Sprite;
private var originalBmd:BitmapData;
private var bmd:BitmapData;
private var bmp:Bitmap;
private var sx:Number = .0;
private var sy:Number = .0;
//Gainer
private var gio:Gainer;
[SWF(backgroundColor="0x000000", frameRate="32")]
public function Main()
{
gio = new Gainer();
var smoother:Convolution = new Convolution(Convolution.MOVING_AVERAGE);
var scaler:Scaler = new Scaler(0.36, 0.6, 0, stage.stageWidth, Scaler.LINEAR, true);
var smoother2:Convolution = new Convolution(Convolution.MOVING_AVERAGE);
var scaler2:Scaler = new Scaler(0.36, 0.6, 0, stage.stageHeight, Scaler.LINEAR, true);
//スケーラー、スムーサー
gio.analogInput(1).filters = [smoother, scaler];
gio.analogInput(0).filters = [smoother2, scaler2];
Security.loadPolicyFile("http://start-rec.net/crossdomain.xml");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoadCompleteHandler);
loader.load(new URLRequest("http://start-rec.net/data/wonderfl/images/baby.jpg"));
}
private function imageLoadCompleteHandler(event:Event):void
{
container = new Sprite();
addChild(container);
bmp = Bitmap(event.target.content);
originalBmd = bmp.bitmapData;
bmd = originalBmd.clone();
bmp = new Bitmap(bmd);
container.addChild(bmp);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler(event:Event):void
{
//sx += ((stage.stageWidth / 2 - stage.mouseX) * 0.1 - sx) * 0.1;
//sy += ((stage.stageHeight / 2 - stage.mouseY) * 0.1 - sy) * 0.1;
//加速度
sx += ((stage.stageWidth / 2 - gio.analogInput(1).value) * 0.1 - sx) * 0.2;
sy += ((stage.stageHeight / 2 - gio.analogInput(0).value) * 0.1 - sy) * 0.2;
bmd.draw(originalBmd);
var mapFilter:DisplacementMapFilter = new DisplacementMapFilter(bmd, new Point(), BitmapDataChannel.RED, BitmapDataChannel.RED, sx, sy, "wrap", 0, 0);
bmp.filters = [mapFilter];
bmd.draw(container);
bmd.applyFilter(bmd, bmd.rect, new Point(), BLUR);
bmd.draw(container);
}
}
}