坐标算法:如图
算法实现:
Ball.as
package
{
import flash.display.Sprite;
public class Ball extends Sprite
{
public var radius:Number;
public var color:uint;
public function Ball (radius:Number,color:uint)
{
this.radius=radius;
this.color=color;
Init ();
}
public function Init ():void
{
graphics.beginFill (color);
graphics.drawCircle (0,0,radius);
graphics.endFill ();
}
}
}
Rotation.as
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Rotation extends Sprite
{
private var ball:Ball;
private var vAngle:Number=0.05;
public function Rotation ()
{
ball=new Ball(20,0xFF0000);
addChild (ball);
ball.x=Math.random()*stage.stageWidth;
ball.y=Math.random()*stage.stageHeight;
addEventListener (Event.ENTER_FRAME,EnterFrame);
}
private function EnterFrame (e:Event):void
{
var x1:Number=ball.x-stage.stageWidth/2;
var y1:Number=ball.y-stage.stageHeight/2;
var x2:Number=x1*Math.cos(vAngle)-y1*Math.sin(vAngle);//逆时针旋转
var y2:Number=y1*Math.cos(vAngle)+x1*Math.sin(vAngle);//逆时针旋转
//var x2:Number=x1*Math.cos(vAngle)+y1*Math.sin(vAngle);顺时针旋转
//var y2:Number=y1*Math.cos(vAngle)-x1*Math.sin(vAngle); 顺时针旋转
ball.x=stage.stageWidth/2+x2;
ball.y=stage.stageHeight/2+y2;
}
}
}
posted @
2009-01-06 17:04
HelloCG
阅读(
240)
评论()
编辑
收藏
举报