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/95qh
*/
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:QuarterArc = new QuarterArc();
private var qa2:QuarterArc = new QuarterArc();
public function FlashTest() {
// write as3 code here..
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
this.addChild(qa);
this.addChild(qa2);
this.addChild( new Stats() );
qa.y = 465;
qa2.y = 465;
}
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);
qa2.setParams(265, 30, this.stage.mouseX / 465, getColor(this.stage.mouseX / 465));
qa.setParams(300, 30, 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();
}
}