画椭圆
package
{
import flash.display.Sprite;
public class Ball extends Sprite
{
public var radius:Number;
public var color:uint;
public function Ball(radius:Number=10,color:uint=0Xff0000)
{
this.radius = radius;
this.color = color;
draw();
}
public function draw():void
{
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}
}
}
{
import flash.display.Sprite;
public class Ball extends Sprite
{
public var radius:Number;
public var color:uint;
public function Ball(radius:Number=10,color:uint=0Xff0000)
{
this.radius = radius;
this.color = color;
draw();
}
public function draw():void
{
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill();
}
}
}
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
private var ball:Ball;
private var angle:Number=0;
private var centerX:Number = 300;
private var centerY:Number = 200;
private var radiusX:Number = 200;
private var radiusY:Number = 100;
private var speed:Number = 0.1;
private var s:Sprite;
public function Main()
{
init();
}
private function init():void
{
//trace(Math.sin(0));=0
//trace(Math.cos(0));=1
ball = new Ball ;
addChild(ball);
ball.x = 300;
ball.y = 300;
s=new Sprite;
addChild(s);
s.graphics.lineStyle(1,0xff0000);
s.graphics.moveTo(ball.x,ball.y);
addEventListener(Event.ENTER_FRAME,_onEnterFrame);
}
private function _onEnterFrame(e:Event):void
{
ball.x = centerX + Math.sin(angle) * radiusX;
ball.y = centerY + Math.cos(angle) * radiusY;
s.graphics.lineTo(ball.x,ball.y);
angle += speed;
}
}
}
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
private var ball:Ball;
private var angle:Number=0;
private var centerX:Number = 300;
private var centerY:Number = 200;
private var radiusX:Number = 200;
private var radiusY:Number = 100;
private var speed:Number = 0.1;
private var s:Sprite;
public function Main()
{
init();
}
private function init():void
{
//trace(Math.sin(0));=0
//trace(Math.cos(0));=1
ball = new Ball ;
addChild(ball);
ball.x = 300;
ball.y = 300;
s=new Sprite;
addChild(s);
s.graphics.lineStyle(1,0xff0000);
s.graphics.moveTo(ball.x,ball.y);
addEventListener(Event.ENTER_FRAME,_onEnterFrame);
}
private function _onEnterFrame(e:Event):void
{
ball.x = centerX + Math.sin(angle) * radiusX;
ball.y = centerY + Math.cos(angle) * radiusY;
s.graphics.lineTo(ball.x,ball.y);
angle += speed;
}
}
}