forked from: forked from: BitmapDataSample8
/**
* Copyright hacker_nf9cwadf ( http://wonderfl.net/user/hacker_nf9cwadf )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lxwy
*/
// forked from dali's forked from: BitmapDataSample8
// forked from nutsu's BitmapDataSample8
// forked from nutsu's BitmapDataSample7
// forked from nutsu's BitmapDataSample5
// forked from nutsu's BitmapDataSample4
// forked from nutsu's BitmapDataSample3
// forked from nutsu's BitmapDataSample1
package {
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.display.BlendMode;
import flash.geom.Point;
import flash.display.BitmapDataChannel;
import flash.filters.DisplacementMapFilter;
import flash.filters.BlurFilter;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width=465,height=465,backgroundColor=0,frameRate=30)]
public class BitmapDataSample8 extends Sprite {
private var bmpdata:BitmapData;
private var sprite:Sprite;
private var matrix:Matrix;
private var colortrans:ColorTransform;
private var filter:DisplacementMapFilter;
private const ZERO_P:Point = new Point(0, 0);
private const BLUR:BlurFilter = new BlurFilter(2,2,2);
public function BitmapDataSample8() {
//BitmapDataを作成して表示リストに追加
bmpdata = new BitmapData( 465, 465, false, 0 );
addChild( new Bitmap(bmpdata) );
//グラフィックの生成
sprite = newFig( 0, 0, 40, 0xFFFFFF );
//Matrix,ColorTransformの初期化
matrix = new Matrix();
colortrans = new ColorTransform();
//エフェクトの初期化
var mapBitmap:BitmapData = new BitmapData( 465, 465, false, 0 );
var mapPoint:Point = mapBitmap.rect.topLeft;
var componentX:uint = BitmapDataChannel.RED;
var componentY:uint = BitmapDataChannel.GREEN;
var scaleX:Number = 256;
var scaleY:Number = 256;
var r:uint = 128 + 2;
var g:uint = 128 + 1;
var b:uint = 128;
var col:uint = r << 16 | g << 8 | b;
mapBitmap.fillRect( mapBitmap.rect, col );
filter = new DisplacementMapFilter( mapBitmap, mapPoint, componentX, componentY, scaleX, scaleY );
//イベント
addEventListener( Event.ENTER_FRAME, enterframe );
stage.addEventListener( MouseEvent.CLICK, reset );
}
private function enterframe(e:Event):void {
//エフェクトの適用
bmpdata.applyFilter( bmpdata, bmpdata.rect, bmpdata.rect.topLeft, filter );
//変形
matrix.identity();
var s:Number = Math.random()*2;
matrix.scale( s, s );
matrix.rotate( Math.PI * Math.random() );
matrix.translate( mouseX, mouseY );
//色変換
colortrans.greenMultiplier = mouseX / 465;
colortrans.blueMultiplier = mouseY / 465;
colortrans.alphaMultiplier = Math.random();
//BitmapDataへ描画
bmpdata.draw( sprite, matrix, colortrans, BlendMode.ADD );
bmpdata.applyFilter(bmpdata, bmpdata.rect, ZERO_P, BLUR);
}
private function reset(e:MouseEvent):void {
bmpdata.fillRect( bmpdata.rect, 0xFF000000 );
}
private function newFig( cx:Number, cy:Number, size:Number, col:uint ):Sprite {
//中心(cx,cy), 幅高さsize, 色col のグラフィックを生成
var shape:Sprite = new Sprite();
shape.graphics.lineStyle( 0, 0x000000, 0.3 );
shape.graphics.beginFill( col );
shape.graphics.drawCircle( cx, cy, size*0.5 );
shape.graphics.drawCircle( cx, cy, size*0.4 );
var w:Number = size * 0.6;
var h:Number = size * 0.15;
shape.graphics.drawRect( cx - w/2, cy - h/2, w, h );
shape.graphics.endFill();
return shape;
}
}
}