チョークのかすれ
/**
* Copyright sanesashi ( http://wonderfl.net/user/sanesashi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rOpi
*/
// チョークのかすれ
// BitmapData, pixelDissolve
// code from http://www.adobe.com/jp/devnet/flash/articles/kokuban_in.html
package {
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.geom.ColorTransform;
import flash.display.Sprite;
import flash.display.Graphics;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.BlurFilter;
public class FlashTest extends Sprite {
private var canvas_bd:BitmapData;
public function FlashTest() {
var sw:Number = this.stage.stageWidth;
var sh:Number = this.stage.stageHeight;
canvas_bd = new BitmapData(sw, sh, true, 0xff009900 );
this.addChild(new Bitmap(canvas_bd));
draw(50, 50, 400, 400, 30);
}
// x: 現在のマウスx座標
// y: 現在のマウスy座標
// px: 直前のマウスx座標
// py: 直前のマウスy座標
// h: チョークの太さ
public function draw( x:int, y:int ,px:int, py:int, h:int ):void {
var dx:int = x - px;
var dy:int = y - py;
var w:Number = Math.sqrt( dx*dx + dy*dy );
var rad:Number = Math.atan2( dy, dx );
var rect:Rectangle = new Rectangle( 0, 0, w, h );
var num:int = w*h*0.7;
var draw_bf:BlurFilter = new BlurFilter( 2, 2, 1 );
var draw_ctf:ColorTransform = new ColorTransform( 1, 1, 1, 0.8 );
var draw_seed:int = int( 0xff * Math.random() );
// かすれ処理
var draw_bd:BitmapData = new BitmapData( w, h, true, 0xffffffff );
draw_bd.pixelDissolve( draw_bd, rect, rect.topLeft, draw_seed, num, 0x00ffffff );
draw_bd.applyFilter( draw_bd, rect, rect.topLeft, draw_bf );
// 転写用変換マトリックス
var draw_mtx:Matrix = new Matrix();
draw_mtx.translate( -h/2, -h/2 );
draw_mtx.rotate( rad );
draw_mtx.translate( px, py );
// 転写
canvas_bd.draw( draw_bd, draw_mtx, draw_ctf );
//px = x;
//py = y;
}
}
}