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

漫画っぽい集中線 Timer版

漫画っぽい集中線をかく
* @author minon

切り替わるタイミングを
EnterFrameではなく
Timerに変更。
by umi_kappa
/**
 * Copyright umi_kappa ( http://wonderfl.net/user/umi_kappa )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/v3oW
 */

// forked from minon's 漫画っぽい集中線
/**
 * 漫画っぽい集中線をかく
 * @author minon
 */
 /*
 切り替わるタイミングを
 EnterFrameではなく
 Timerに変更。
 by umi_kappa
 */

package  {
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.utils.*;
	
	public class LineTest extends Sprite {
		private var _canvas:BitmapData;
		
		public function LineTest() {
			_canvas = new BitmapData( 465, 465, true, 0 );
			this.addChild( new Bitmap( _canvas ) );
			
			_drawLine( _canvas );
			
			var timer:Timer = new Timer(100);
			timer.addEventListener("timer",_render);
			timer.start();
		}
		
		private function _render(e:TimerEvent):void {
			_canvas.fillRect( new Rectangle( 0, 0, 465, 465 ), 0 );
			_drawLine( _canvas );
		}
		
		
		public function _drawLine( bmp:BitmapData ):void {
			var line:Sprite = new Sprite();
			var g:Graphics = line.graphics;
			drawTriangle( g );
			
			var a:int = 2;
			var len:int = stage.width / 2 * Math.sqrt(2);
			var d:int = 360;
			
			while ( 0 < d ) {
				var x:Number = Math.sin( d * Math.PI / 180 ) * len + stage.width / 2;
				var y:Number = Math.cos( d * Math.PI / 180 ) * len + stage.height / 2;
				
				var mtx:Matrix = new Matrix();
				mtx.scale( 5, Math.random() * len + len/2 );
				//mtx.scale(x,y); 拡大・縮小
				mtx.rotate( ( -d ) * Math.PI / 180 );
				//mtx.rotate(角度);
				mtx.translate( x, y );
				//mtx.translate(x,y); 指定された量だけ行列を平行移動
				
				bmp.draw( line, mtx );
				
				d -= Math.round( Math.random() * a );
			}
		}
		
		//線(細長い3角形)を書く
		public function drawTriangle( g:Graphics ):void {
			g.beginFill(0x0000ff);
			//beginFill 塗りの色
			g.moveTo( -0.5, 0 );
			//描画位置を移動
			g.lineTo( 0.5, 0 );
			g.lineTo( 0, -0.5 );
			g.lineTo( -0.5, 0 );
			//描画位置~lineTo(x,y)まで線を引く
		}
		
	}
	
}