flash actionscript3.0

今天学习下圆运动

以太阳 地球 月亮为例

主要内容是

                earth.x=sun.x+120*Math.cos(n);
                earth.y=sun.y+120*Math.sin(n);

sun.x sun.y是圆的中心点

120是圆的半径

n 是角度0~2PI


package 
{

	import flash.display.Sprite;
	import flash.events.*;
	import flash.geom.*;
	import flash.filters.*;
	import flash.display.DisplayObject;

	public class yuan extends Sprite
	{
		private var sun,earth,moon:Sprite=new Sprite();//创建容器
		private var centerX:Number=stage.stageWidth/2;
		private var centerY:Number=stage.stageHeight/2;
		private var j:Number=0;
		private var n:Number=0;
		public function yuan()
		{
			
			sun=new Sprite();
			addChild(sun);
		    sun.graphics.beginFill(0xffcc00);
		    sun.graphics.drawCircle(0,0,30);
		    sun.graphics.endFill();			
			
			//太阳位置在舞台中间
			sun.x=centerX;
			sun.y=centerY;
			sun.z=0;			
			//对太阳使用模糊
			sun.filters=[new BlurFilter(20,20,BitmapFilterQuality.HIGH)];
						
						  
			moon=new Sprite();
			addChild(moon);
		    moon.graphics.beginFill(0xcccccc);
		    moon.graphics.drawCircle(0,0,4);
		    moon.graphics.endFill();
			moon.x=0;
			moon.y=0;
			moon.z=0;
			earth=new Sprite();
			addChild(earth);
		    earth.graphics.beginFill(0x0033FF);
		    earth.graphics.drawCircle(0,0,15);
		    earth.graphics.endFill();
			earth.x=0;
			earth.y=0;
			earth.z=0;	
			
           //加入帧事件
			addEventListener(Event.ENTER_FRAME,Run);
		}
		public function Run(e:Event):void{
			
				//地球相对于太阳位置
				n+=0.05;
				earth.x=sun.x+120*Math.cos(n);
				earth.y=sun.y+120*Math.sin(n);
                if(n>=6.28) n=0;//6.28是2个PI意思			
			
			    //月亮相对于地球位置
                j+=0.2;
				moon.x=earth.x+30*Math.cos(j);
				moon.y=earth.y+30*Math.sin(j);
                if(j>=6.28) j=0;
				
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值