zoukankan      html  css  js  c++  java
  • 下雪效果

    displaySnow();
    
    function displaySnow() {
    	for (var i:int=0; i<40; i++) {
    		var snowFlake:SnowFlake=new SnowFlake(400);
    		addChild(snowFlake);
    
    		snowFlake.x=Math.random()*550;
    		snowFlake.y=Math.random()*400;
    
    		snowFlake.alpha=0.2+Math.random()*5;
    
    		snowFlake.scaleX=snowFlake.scaleY=0.4+Math.random()*1.5;
    	}
    }
    
    //===================雪花类SnowFlake.as===================
    package {
    	import flash.display.MovieClip;
    	import flash.events.Event;
    
    	public class SnowFlake extends MovieClip {
    		private var radians:Number=0;
    		private var speed:Number=0;
    
    		private var maxHeight:Number;
    
    		public function SnowFlake(maxHeight_:Number) {
    			speed=0.5*Math.random();//[0.01,0.51)
    
    			maxHeight=maxHeight_;
    
    			this.addEventListener(Event.ENTER_FRAME,snowing);
    		}
    
    		private function snowing(e:Event):void {
    			radians+=speed;
    
    			//如果此处不用Math.cos(),而用普通的this.x+=Math.random()*2,左右晃动效果会很明显
    			this.x+=Math.cos(radians);
    			this.y+=2;
    
    			if (this.y>maxHeight) {
    				this.y=-20;
    			}
    		}
    	}
    }
    
  • 相关阅读:
    centos7 setfacl权限
    三层交换机做DHCP的一些疑问
    python3 re模块
    python3 的小爬虫
    初学python的一些简单程序(2)
    python3 字典
    python3 元组
    python3列表
    初学python的一些简单程序(1)
    python3的字符串操作
  • 原文地址:https://www.cnblogs.com/leon3286/p/1807203.html
Copyright © 2011-2022 走看看