In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: forked from: forked from: forked from: forked from: flash on 2010-2-21

inFamous で毒食らったらこんなんなる
/**
 * Copyright kkstudio ( http://wonderfl.net/user/kkstudio )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xH5c
 */

// forked from mhayashi's forked from: forked from: forked from: forked from: forked from: flash on 2010-2-21
// forked from mhayashi's forked from: forked from: forked from: forked from: flash on 2010-2-21
// forked from mhayashi's forked from: forked from: forked from: flash on 2010-2-21
// forked from mhayashi's forked from: forked from: flash on 2010-2-21
// forked from mhayashi's forked from: flash on 2010-2-21
// forked from mhayashi's flash on 2010-2-21

// inFamous で毒食らったらこんなんなる

package {
    import flash.display.Sprite;
	import flash.display.Bitmap;
    import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.geom.Matrix;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.filters.BlurFilter;
	import flash.filters.DisplacementMapFilter;
	
	[SWF(width=465, height=465, backgroundColor=0, framerate=30)]
    public class BitmapDataSample extends Sprite {

		private var bmpdata:BitmapData;
		private var sprite:Sprite;
		private var matrix:Matrix;
		private var colortrans:ColorTransform;
		private var filter:DisplacementMapFilter;
		
        public function BitmapDataSample() {
			bmpdata = new BitmapData( 465, 465, false, 0 );
			addChild( new Bitmap(bmpdata) );

			sprite = newFig( 0, 0, 140, 0xFFFFFF );

			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 = 8;
			var scaleY:Number = 8;
			mapBitmap.perlinNoise(240, 240, 2, 0, false, false);
			filter = new DisplacementMapFilter( mapBitmap, mapPoint, componentX, componentY, scaleX, scaleY );
			
			addEventListener( Event.ENTER_FRAME, enterFrame );
			stage.addEventListener( MouseEvent.CLICK, reset );
        }

		// ENTER_FRAME のイベントリスナー
		private function enterFrame(e:Event):void {
			matrix.identity();

			var s:Number = Math.random()*2;
			matrix.scale(s, s);

			matrix.rotate(Math.PI * Math.random());

			matrix.translate(mouseX, mouseY);

			bmpdata.applyFilter(bmpdata, bmpdata.rect, bmpdata.rect.topLeft, filter);
			
			// マウスの座標を色の変換に使っているので、ポインタの位置によって色が変わる
			// かつ、グラデーションがかかる
			colortrans.greenMultiplier = mouseX / 465;
			colortrans.blueMultiplier = mouseY / 465;
			colortrans.alphaMultiplier = Math.random();
			
			bmpdata.draw(sprite, matrix, colortrans);
		}

		// マウスクリックのイベントリスナー
		private function reset(e:MouseEvent):void {
			bmpdata.fillRect( bmpdata.rect, 0xFF000000 );
		}
		
		private function newFig( cx:Number, cy:Number, size:Number, color:uint ):Sprite {
			var shape:Sprite = new Sprite();
			shape.graphics.lineStyle( 0, 0x000000, 0.3 );
			shape.graphics.beginFill( color );

			shape.graphics.drawCircle( cx, cy, size*0.5 );
			shape.graphics.drawCircle( cx, cy, size*0.4 );

			var w:Number = size * 0.1;
			var h:Number = size * 0.05;
			shape.graphics.drawRect(
				cx - w/2,		// 横の位置(円の中心)
				cy - h/2,		// 縦の位置(円の中心)
				w,
				h );
			shape.graphics.endFill();
			return shape;
		}
    }
}