http://btbtd.org/topic/flash/DrawRectCircle/Main.swf
http://btbtd.org/topic/flash/DrawRectCircle/DrawRectCircle.zip
- package
- {
- import flash.display.Sprite;
- import flash.utils.Timer;
- import flash.events.TimerEvent;
- public class DrawRectCircle extends Sprite
- {
- private var shadow:Sprite;
-
- private var xMinPoint:Number = 0;
- private var xMidPoint:Number = 0;
- private var xMaxPoint:Number = 0;
-
- private var yMinPoint:Number = 0;
- private var yMidPoint:Number = 0;
- private var yMaxPoint:Number = 0;
-
- private var runAllMs:Number = 1000;
- private var stepMs:Number = 0;
-
- private var timer:Timer;
- private var percentCount:Number = 0;
-
-
- public function DrawRectCircle( pX:int = 0, pY:int = 0 )
- {
- this.x = pX;
- this.y = pY;
-
- shadow = new Sprite();
- addChild( shadow );
- }
-
- public function get getTimer():Timer
- {
- return this.timer;
- }
-
- public function drawCircle( pWidth:int = 50, pHeight:int = 50 ):void
- {
- this.graphics.clear();
- this.graphics.lineStyle( 0, 0, 0 );
- this.graphics.beginFill( 0x000000, .1 );
- this.graphics.drawRect( 0, 0, pWidth, pHeight );
- this.graphics.endFill();
-
- this.xMidPoint = pWidth / 2;
- this.xMaxPoint = pWidth;
-
- this.yMidPoint = pHeight / 2;
- this.yMaxPoint = pHeight;
-
-
- stepMs = runAllMs / 25;
-
- if( timer )
- {
- if( timer.running )
- {
- timer.stop();
- timer.removeEventListener( TimerEvent.TIMER, onTimerEvent );
- timer = null;
- }
- }
-
- percentCount = 0;
-
- timer = new Timer( stepMs )
- timer.addEventListener( TimerEvent.TIMER, onTimerEvent );
- timer.start();
-
- //makeGraphic();
-
- }
-
- private function onTimerEvent( event:TimerEvent ):void
- {
- percentCount += 4;
-
- if( percentCount > 100 )
- {
- timer.stop();
- return;
- }
-
- makeGraphic( percentCount );
-
- event.updateAfterEvent();
- }
-
- private function getPoint( knowPoint:Number, degree:Number, midPoint:Number = 0 ):Number
- {
- if( !midPoint)
- {
- midPoint = xMidPoint;
- }
- var result:Number = knowPoint + (degree % 45) / 45 * midPoint;
- return result;
- }
-
-
- /*
- var degree:Number = percent / 100 * 360;
- var percent:Number 100 / 360 * 60;
- var point:Number = xMidPoint + (degree % 45) / 45 * xMidPoint;
- */
- private function makeGraphic( percent:Number = 0 ):void
- {
- var degree:Number = percent / 100 * 360;
-
- //degree = 230.4;
-
- var temp:Number = 0;
-
- shadow.graphics.clear();
- shadow.graphics.lineStyle( 0, 0, 0 );
- shadow.graphics.beginFill( 0x000000, .35 );
-
- shadow.graphics.moveTo( xMidPoint, yMidPoint )
-
- trace( 'degree: ' + degree +', '+( degree % 45 ) )
-
- if( degree > 0 && degree < 45 )
- {
- shadow.graphics.lineTo( xMidPoint, 0 );
-
- shadow.graphics.lineTo( getPoint(xMidPoint, degree), 0 );
- }
-
- if( degree >= 45 )
- {
- shadow.graphics.lineTo( xMidPoint, 0 );
- shadow.graphics.lineTo( xMaxPoint, 0 );
-
- if( degree > 45 && degree < 90 )
- {
- shadow.graphics.lineTo( xMaxPoint, getPoint(0, degree, yMidPoint) );
- }
- }
-
- if( degree >= 90 )
- {
- shadow.graphics.lineTo( xMaxPoint, yMidPoint );
-
- if( degree > 90 && degree < 135 )
- {
- shadow.graphics.lineTo( xMaxPoint, getPoint(yMidPoint, degree, yMidPoint) );
- }
- }
-
- if( degree >= 135 )
- {
- shadow.graphics.lineTo( xMaxPoint, yMaxPoint );
-
- if( degree > 135 && degree < 180 )
- {
- shadow.graphics.lineTo( xMaxPoint - getPoint(xMidPoint, degree) + xMidPoint, yMaxPoint );
- }
- }
-
- if( degree >= 180 )
- {
- shadow.graphics.lineTo( xMidPoint, yMaxPoint );
-
- if( degree > 180 && degree < 225 )
- {
- shadow.graphics.lineTo( xMaxPoint - getPoint(xMidPoint, degree), yMaxPoint );
- }
- }
-
- if( degree >= 225 )
- {
- shadow.graphics.lineTo( 0, yMaxPoint );
-
- if( degree > 225 && degree < 270 )
- {
- shadow.graphics.lineTo( 0, yMaxPoint - getPoint(yMidPoint, degree, yMidPoint) + yMidPoint );
- }
- }
-
- if( degree >= 270 )
- {
- shadow.graphics.lineTo( 0, yMidPoint );
-
- if( degree > 270 && degree < 315 )
- {
- shadow.graphics.lineTo( 0, yMaxPoint - getPoint(yMidPoint, degree, yMidPoint) );
- }
- }
-
- if( degree >= 315 )
- {
- shadow.graphics.lineTo( 0, 0 );
-
- if( degree > 315 && degree < 360 )
- {
- shadow.graphics.lineTo( getPoint(0, degree), 0 );
- }
- }
-
- if( degree >= 360 )
- {
- shadow.graphics.lineTo( xMidPoint, 0 );
- }
-
- shadow.graphics.lineTo( xMidPoint, yMidPoint );
- shadow.graphics.endFill();
- }
-
- }
-
- }
|