package
{
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.Event;
import flash.geom.Point;
public class Main extends Sprite
{
private var cirlce:Shape;
private var line:Shape;
private var A:int = 100;
private var n:int = 0;
public function Main()
{
init();
}
private function init():void
{
cirlce=new Shape();
cirlce.graphics.beginFill(0x00ff00);
cirlce.graphics.drawCircle(0,0,20);
cirlce.graphics.endFill();
addChild(cirlce);
cirlce.x = 250;
cirlce.y = 100;
line=new Shape();
line.graphics.lineStyle(1);
line.graphics.beginFill(0x00ff00);
line.graphics.drawCircle(0,0,2);
line.graphics.endFill();
addChild(line);
line.x = 250;
line.y = 20;
addEventListener(Event.ENTER_FRAME,onRun);
}
private function onRun(event:Event):void
{
n+=3;
line.graphics.clear();
line.graphics.lineStyle(1);
line.graphics.beginFill(0x00ff00);
line.graphics.drawCircle(0,0,2);
line.graphics.endFill();
line.graphics.moveTo(0,0);
cirlce.x=250+A*Math.cos(n%360*Math.PI/180);
var p:Point=line.globalToLocal(new Point(cirlce.x,cirlce.y));
line.graphics.lineTo(p.x,p.y);
line.graphics.drawCircle(p.x,p.y,2);
}
}
}
呵呵,写了一个简单的运动效果,就是一条线绑定一个小球左右摆动。进行运动后,你会发现很像一个程序。这个只是很小的动画实现。
cirlce.x=250+A*Math.cos(n%360*Math.PI/180); 比较好玩 就是根据这个公式来实验。大家可以试试这些公式,对制作公式有一些作用
967





