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: 1/4 の円弧描画クラス

/**
 * Copyright keno42 ( http://wonderfl.net/user/keno42 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/n4NO
 */

// forked from keno42's 1/4 の円弧描画クラス
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import net.hires.debug.Stats;
    [SWF(backgroundColor="0")]
    public class FlashTest extends Sprite {
        private var qa:Vector.<QuarterArc> = new Vector.<QuarterArc>;
        private var qa2:Vector.<QuarterArc> = new Vector.<QuarterArc>;
        private const NUM:Number = 30;
        private const WIDTH:Number = 6;
        public function FlashTest() {
            // write as3 code here..
            this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
            this.addChild( new Stats() );
            for( var i:int = 0; i < NUM; i++ ){
                qa.push(new QuarterArc());
                qa2.push(new QuarterArc());
                qa[i].y = qa2[i].y = 465;
                this.addChild(qa[i]);
                this.addChild(qa2[i]);
            }
        }
        private function onEnterFrame(e:Event):void{
            graphics.clear();
            graphics.lineStyle(0, 0x00FF00);
            graphics.moveTo(stage.mouseX, stage.mouseY-10);
            graphics.lineTo(stage.mouseX, stage.mouseY+10);
            graphics.moveTo(stage.mouseX-10, stage.mouseY);
            graphics.lineTo(stage.mouseX+10, stage.mouseY);
            for( var i:int = 0; i < NUM; i++ ){
                qa2[i].setParams((WIDTH+1)*(2*i), WIDTH, this.stage.mouseX / 465, getColor(this.stage.mouseX / 465));
                qa[i].setParams((WIDTH+1)*(2*i+1), WIDTH, 1 - this.stage.mouseY / 465, getColor(1 - this.stage.mouseY / 465));
            }
        }
        private function getColor(rate:Number):int{
            var ret:int = 0;
            var temp:Number;
            if( rate < 0.5 ){
                temp = rate / 0.5;
                ret = 0xFF0000;
                ret |= int( temp * 255 ) << 8;
            } else {
                temp = (1 - rate) / 0.5;
                ret = 0x00FF00;
                ret |= int( temp * 255) << 16;
            }
            return ret;
        }
    }
}
	import flash.display.Graphics;
	import flash.display.Sprite;
	
	/**
	 * 1/4の円弧を描く
	 * @author Kenichi UENO
	 */
	class QuarterArc extends Sprite
	{
		private var maskSp:Sprite = new Sprite();
		public function QuarterArc()
		{
			this.mask = maskSp;
			this.addChild( maskSp );
		}
                
                // 内側の半径、幅、割合(0~1)、色
		public function setParams(radius:Number, width:Number, rate:Number, color:int):void {
			var radian:Number = rate < 0.5?Math.PI * 0.5 * rate:Math.PI * 0.5 * (rate-0.5);
			var maskG:Graphics = maskSp.graphics;
			var outsideR:Number = radius + width;
                        graphics.clear();
                        maskG.clear();
			graphics.beginFill(color);
			graphics.drawCircle(0, 0, outsideR);
			graphics.drawCircle(0, 0, radius);
			maskG.beginFill(0xFF);
			maskG.lineTo(outsideR, 0);
			if( rate < 0.5 ){
				maskG.lineTo(outsideR, -outsideR * Math.tan( radian ));
			} else {
				maskG.lineTo(outsideR, -outsideR);
				maskG.lineTo(outsideR * (1-Math.tan( radian )), -outsideR);
			}
			maskG.lineTo(0, 0);
			maskG.endFill();
		}
		
	}