うずまき
参考
http://level0.kayac.com/#!2009/11/matrix_with_getbounds.php
http://d.hatena.ne.jp/habu024/20090921/125353362
/**
* Copyright otherone ( http://wonderfl.net/user/otherone )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uIAC
*/
package
{
import com.bit101.components.HSlider;
import com.bit101.components.PushButton;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import flash.filters.DisplacementMapFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.text.TextField;
[SWF(width = 465,height = 465,frameRate = 24,backgroundColor = 0)]
/**
* ...
* @author moriya
*
*
*
* 参考
* http://level0.kayac.com/#!2009/11/matrix_with_getbounds.php
*http://d.hatena.ne.jp/habu024/20090921/125353362
*
*/
public class Main extends Sprite
{
private var neko:Bitmap;
private var speed:Number;
private var radius:Number;
private var angle:Number
private var xpos:Number;
private var ypos:Number;
private var moving:Boolean = true;//動いてるかどうか
//ステージの中心
private var centerX:Number = stage.stageWidth / 2;
private var centerY:Number = stage.stageHeight / 2;
private const STW:int = stage.stageWidth
private const STH:int = stage.stageHeight;
private var nullSp:Sprite = new Sprite()
private var base:MovieClip = new MovieClip();
private var bmp_data:BitmapData = new BitmapData(STW, STH, true, 0x00000000);
private var matrix:Matrix = new Matrix(1, 0, 0, 1, 0, 0);
private var color:ColorTransform = new ColorTransform(1,1,1,1,0,0,0,0);
private var rect:Rectangle = new Rectangle(0, 0, STW, STH);
private var bmp:Bitmap = new Bitmap(bmp_data);
private var blur:BlurFilter = new BlurFilter();
private var hSlider:HSlider;
private var tf:TextField = new TextField();
private var _imgLoader:Loader;
private var _imgLoaderInfo:LoaderInfo;
private var _rot:uint;
private var button:PushButton;
private var button2:PushButton;
private var isAuto:Boolean;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var url:String = "http://assets.wonderfl.net/images/related_images/2/25/25d8/25d8c731e4500b0d32bae8a6611728abd078d554";
var urlReq:URLRequest = new URLRequest(url);
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
_imgLoader = new Loader();
_imgLoaderInfo = _imgLoader.contentLoaderInfo;
_imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageloaded);
_imgLoader.load(urlReq, context);
}
private function onImageloaded(e:Event):void
{
radius = 0, speed = 0.2;
var bmd:BitmapData = new BitmapData(_imgLoader.width, _imgLoader.height);
bmd.draw(_imgLoader);
neko = new Bitmap(bmd);
addChild(neko);
var _rto:Number = 0;
if (neko.width > neko.height) {
_rto = STW/neko.width ;
neko.width = STW,neko.height = neko.height*_rto;
} else {
_rto = STH/neko.height ;
neko.height = STH,neko.width = neko.width*_rto;
}
neko.x = centerX - neko.width * 0.5;
neko.y = centerY - neko.height * 0.5;
base.x = centerX, base.y = centerY;
addChild(base);
//base.visible = false;
matrix.translate(centerX, centerY);
bmp_data.draw(base, matrix);
blur.blurX = 15;
blur.blurY = 15;
bmp.filters = [blur];
// 横方向スライダーの準備
hSlider = new HSlider(this);
hSlider.width = STW-20;
hSlider.addEventListener(Event.CHANGE, onHSliderChange);
hSlider.x = centerX - hSlider.width * 0.5;
hSlider.y = STH - hSlider.height * 0.5-10;
//labelHSlider = new Label(panel, 60, 100);
//labelHSlider.text = "0.0";
hSlider.value = 50;
//
tf.text = '0';
tf.textColor = 0xFFFFFF;
tf.x = centerX - tf.width * 0.5;
tf.height = 20;
tf.y = STH - 40;
addChild(tf);
//
button = new PushButton(this, 0, 0,'uzumakiOFF', guruguruOff);
button.x = STW - button.width - 10, button.y = STH - button.height * 2;
button2 = new PushButton(this, 0, 0,'autoOFF', autOff);
button2.x = STW - button2.width*2 - 20, button2.y = STH - button2.height * 2;
//
addEventListener(Event.ENTER_FRAME, fnUpdate);
}
private function fnUpdate(e:Event):void
{
if (hSlider.value == 100) hSlider.value = 20;
hSlider.value ++;
_onHSliderChange();
}
private function autOff(e:MouseEvent):void
{
isAuto = !isAuto;
isAuto ? removeEventListener(Event.ENTER_FRAME, fnUpdate):addEventListener(Event.ENTER_FRAME, fnUpdate);
isAuto ? button2.label = 'autoON':button2.label = 'autoOFF';
}
private function guruguruOff(e:MouseEvent):void
{
base.visible = !base.visible;
base.visible ? button.label = 'uzumakiOFF':button.label = 'uzumakiON';
}
private function onHSliderChange(e:Event):void
{
_onHSliderChange();
}
private function _onHSliderChange():void
{
var radius:Number = (hSlider.value-50) *10;
tf.text = String(Math.round(radius));
//trace(radius)
//線を描く;
base.graphics.clear();
//base.graphics.lineStyle(10, 0xffffff, 0.6);//,false,'normal',null,"round");
base.graphics.moveTo(0, 0);
var setNum:Number = 0;
for (var i:int=0; i<Math.abs(radius); i++)
{
base.graphics.lineStyle(i*0.08, 0xffffff, 1,false,'normal',null,"round");
radius < 0 ? setNum = - i:setNum = i;
angle = setNum * speed;
base.graphics.lineTo(Math.cos(angle) * setNum,Math.sin(angle) * setNum);
}
//bmp_data.dispose();
bmp_data = new BitmapData(STW,STH,true,0x000000);
bmp.bitmapData = bmp_data;
base.rotation = radius*1.5;
_rot =radius*1.5;
//オブジェクトの領域を取得
var _brect:Rectangle = new Rectangle(0, 0, STW, STH);
//(0,0)にオブジェクトの中心を合わせる。(1)
matrix.translate(-(_brect.left + _brect.width / 2), -(_brect.top + _brect.height / 2));
//N度(Math.PI / 回転させる(2)
matrix.rotate(_rot / 180 * Math.PI);
//もとの位置にオブジェクトを移動する。(3)
matrix.translate(_brect.left + _brect.width / 2, _brect.top + _brect.height / 2);
//matrix.x = centerX, matrix.y = centerY;
bmp_data.draw(base, matrix);
var point:Point = new Point(0, -50);
var displacementMapFilter:DisplacementMapFilter =
new DisplacementMapFilter(bmp_data, point, 1, 1, 0, 50, "clamp", 0x00000000);
displacementMapFilter.scaleX=Math.random()*10
displacementMapFilter.scaleY = Math.random() * 10
neko.filters = [displacementMapFilter];
}
}
}