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

クリックでアニメーション
Get Adobe Flash player
by gupon 07 Nov 2009
    Embed
/**
 * Copyright gupon ( http://wonderfl.net/user/gupon )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xlyV
 */

/*
    クリックでアニメーション
*/

package {
	import caurina.transitions.Tweener;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	[SWF(frameRate="60", backgroundColor="#000000")]
	public class drawArc extends Sprite{
		private var graphicsLib:GraphicsLib;
		private var _degree:Number = 0;
		private var flag:Boolean;
		
		public function drawArc(){
			if( stage ) init();
			else addEventListener( Event.ADDED_TO_STAGE, init);
		}
		
		private function init(event:Event=null):void{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			graphicsLib = new GraphicsLib();
			stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
		}
		
		public function get degree():Number{ return _degree };
		public function set degree(value:Number):void{
			_degree = value;
			graphics.clear();
			graphicsLib.drawPie(graphics, 200, 200, 100, _degree, 0);
		}
		
		private function onMouseDownHandler( event:MouseEvent ):void{
			if(flag){
				Tweener.addTween(this, { degree:0, time:3, transition:"linear"});
				flag = false;
			} else {
				Tweener.addTween(this, { degree:360, time:3, transition:"linear"});
				flag = true;
			}
		}
		
	}
}


import flash.display.Graphics;
import flash.geom.Point;

internal class GraphicsLib{
	public function GraphicsLib(){
	}
	
	public function drawPie(g:Graphics,x:Number,y:Number,radius:Number,degree:Number,fromDegree:Number=0):void{
		g.lineStyle(3,0xFFFFFF);
		g.moveTo(x,y);
		
		if( Math.abs(degree) > 360 ) degree %= 360;
		if( Math.abs(fromDegree) > 360 ) fromDegree %= 360;
		if( degree < fromDegree ) throw new Error("no way!");
		
		var div:int = Math.ceil((degree - fromDegree)/10);
		var radians:Number = degree * Math.PI / 180;
		var fromRadians:Number = fromDegree * Math.PI / 180;
		var segment:Number = (radians - fromRadians) / div;
		
		for(var i:int;i<div;i++){
			var _from:Number = segment * i;
			var _to:Number = (i == div-1) ? radians : segment * (i+1);
			if( i == 0 ){
				var startPos:Point = new Point();
				startPos.x = Math.cos(_from) * radius + x;
				startPos.y = Math.sin(_from) * radius + y;
				g.moveTo(startPos.x, startPos.y );
			}
			
			var endPos:Point = new Point();
			endPos.x = Math.cos(_to) * radius + x;
			endPos.y = Math.sin(_to) * radius + y;
			 
			var controlPos:Point = new Point();
			controlPos.y = radius * Math.tan(Math.abs(_to - _from)/2);
			controlPos.x = startPos.x - Math.sin(_from) * controlPos.y; 
			controlPos.y = startPos.y + Math.cos(_from) * controlPos.y;
			
			g.curveTo(controlPos.x, controlPos.y, endPos.x, endPos.y);
			startPos.x = endPos.x;
			startPos.y = endPos.y;
			
			//コントロールポイント表示用
			
			g.lineStyle(0,0xFFFFFF,0);
			g.beginFill(0xFF0000);
			g.drawRect(controlPos.x-2, controlPos.y-2, 4, 4);
			g.endFill();
			g.lineStyle(3,0xFFFFFF,1);
			g.moveTo(endPos.x,endPos.y);
		}
	}
}