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

単位球面上の移動

Get Adobe Flash player
by 178ep3 28 Jul 2009
/**
 * Copyright 178ep3 ( http://wonderfl.net/user/178ep3 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5JBX
 */

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	 [SWF(width=465, height=465, frameRate=30, backgroundColor=0x000000)] 
	public class Sphere extends Sprite
	{
		public function Sphere()
		{
			var i:int = 0;
			var list:Array = [];
			for(i=0; i<19; i++)
			{
				var d:Dot = addChild(new Dot(i))as Dot;
				list.push(d);
			}
			
			addEventListener(Event.ENTER_FRAME,upup);
			
			function upup(e:Event):void
			{
				for(i=0; i<19; i++)
				{
					list[i].loop();
				}
			}
		}
	}
}

	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;

class Dot extends Sprite
{
	private var _x:Number=0;
	private var _y:Number=0;
	private var _z:Number=0;
	
	private var _r:uint = 1;
	
	private var _xyAngle:Number = 0;
	private var _xzAngle:Number = 0;
	private var _xyAdd:Number;
	private var _xzAdd:Number;
	
	private var _rad:uint=100;
	private var _dot:Shape;
		
	public function Dot(setNum:int)
	{
		_xyAngle = setNum*10-90;
		_xzAngle = setNum*20;
		
		this.x = 238;
		this.y = 238;
		
		_xyAdd = 0.5;
		_xzAdd = 1;
		
		init();
	}
		
	private function init():void
	{
		_dot = addChild(new Shape())as Shape;
		with(_dot.graphics)
		{
			beginFill(0xffffff);
			drawCircle(0,0,3);
			endFill();
		}
	}
			
	public function loop():void
	{
		_xyAngle +=_xyAdd;
		_xzAngle +=_xzAdd;
		if(_xyAngle>360)_xyAngle-=360;
		if(_xzAngle>360)_xzAngle-=360;
			
		_x = Math.cos(_xyAngle*Math.PI/180);
		_y = Math.sin(_xyAngle*Math.PI/180);
		_x = _x * Math.cos(_xzAngle*Math.PI/180);
		_z = Math.sqrt(1 - Math.pow(_x,2) - Math.pow(_y,2));
		if(_xzAngle>180)_z*=-1;
		_dot.x = _x*_rad;
		_dot.y = _y*_rad;

		_dot.scaleX = _dot.scaleY = _z+1;
	}
}