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

graphics.curveToを使った遊び

Graphics.curveToを使った遊び
とりあえず適当に作ってみた。
@author okoi
Get Adobe Flash player
by okoi 06 May 2010
/**
 * Copyright okoi ( http://wonderfl.net/user/okoi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/a66F
 */

//
//	Graphics.curveToを使った遊び
//	とりあえず適当に作ってみた。
//	@author okoi
//
package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class Main extends Sprite 
	{
		private static const LINENUM:int = 200;
		private var line:Array = new Array();
		
		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
			
			for ( var i:int = 0; i < LINENUM; i++ )
			{
				var l:Line = new Line();
				l._cx = l._x = stage.stageWidth / 2;
				l._cy = l._y = stage.stageHeight / 2;
				l._r = 100;		// (Line.RADIUS_SIZE / LINENUM * i) + 100;
				l._angle = 360 / LINENUM * i;
				l._power1 = 0.8 - (0.6 / LINENUM * i); 
				line.push( l );
			}
			addEventListener( Event.ENTER_FRAME, Update );
		}

		private function Update( e:Event ) : void 
		{
			var i:int;
			for ( i = 0; i < line.length; i++ )
			{
				line[i].Update( stage.mouseX, stage.mouseY, i );
			}			
			
			graphics.clear();
			graphics.lineStyle( 1, 0 );
			for ( i = 0; i < line.length; i++ )
			{
				var obj:Line = line[i];				
				var rx:Number = Math.cos( obj._angle * Math.PI / 180 ) * obj._r;
				var ry:Number = Math.sin( obj._angle * Math.PI / 180 ) * obj._r;
				graphics.moveTo( obj._x - rx, obj._y - ry );
				graphics.curveTo( obj._cx, obj._cy, obj._x + rx, obj._y + ry );
			}			
		}			
	}
	
}

class Line {
	
	
	public	static const RADIUS_SIZE:int = 50;
	
	public	var _x:Number;
	public	var _y:Number;
	
	public	var _cx:Number;	//	制御点
	public	var _cy:Number;	//	制御点
	public	var _cmx:Number;
	public	var _cmy:Number;
	
	public	var _r:Number;		//	半径
	public	var _angle:Number;
	
	public	var _power1:Number;
	public	var _power2:Number;
	
	public	function Line():void 
	{
		_x = 0;
		_y = 0;
		_cx = 0;
		_cy = 0;
		_cmx = 0;
		_cmy = 0;
		_r = 50;
		_angle = 0;
		
		_power1 = 0.2;
		_power2 = 0.9;
	}
	
	public	function Update(tx:Number, ty:Number, rot:Number ):void 
	{
		if ( Math.abs( tx - _cx ) < 1 && Math.abs( ty - _cy ) < 1 ) return;
		
		_cmx += (tx - _cx) * _power1;
		_cmx *= _power2;
		
		_cmy += (ty - _cy) * _power1;
		_cmy *= _power2;
		
		_cx += _cmx;
		_cy += _cmy;	
		
		_x = tx;
		_y = ty;
		
		//_angle = (_angle + rot) % 360;	//	角度を回転させるとまた違った感じに
	}
	
	
}