看网上的雪花,三方库的,粒子系统,看着很高深复杂,我觉得有点杀鸡用牛刀。
我耍了小聪明,一共三种轨迹,正弦曲线,两种抛物线,然后两种曲线求导(自己求导),得到刚好是x y坐标的变化量 程序可以更简单
package
{
import flash.display.GradientType;
import flash.display.Shape;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.net.SharedObject;
[SWF(width=960,height=560,backgroundColor="#000000")]
public class test_snow extends Sprite
{
private var snow_list:Array = new Array();
private var i:int = 0;
private static const NUM:int = 300;
private var r:int = 1;
public function test_snow()
{
addEventListener(Event.ENTER_FRAME,onEnterFrame);
for(i = 0; i<NUM; i++)
{
var circle:Shape = new Shape();
var x:int = Math.random()*960;
var y:int = Math.random()*560;
var temp:int = Math.random();
if(Math.random() > 0.3)
{
circle.alpha = 0.5;
}
if(Math.random() <0.3)
{
circle.alpha = 0.8;
}
circle.x = x;
circle.y = y;
snow_list.push(circle);
draweEllipse(circle,0, 0);
}
}
private function draweEllipse(circle:Shape, x:int, y:int):void
{
circle.graphics.beginFill(0xffffff);
if(i % 2 == 0)
{
r = 2.5;
}
else if(i % 7 || i % 3 == 0)
{
r = 2;
}
else
{
r = 1.5;
}
circle.graphics.drawCircle(x,y,r);
circle.graphics.endFill();
addChild(circle);
}
private function onEnterFrame(event:Event):void
{
for(i = 0;i < NUM;i++)
{
if(i % 5 == 0)
{
snow_list[i].y += 1;
snow_list[i].x += 2*Math.cos(snow_list[i].y/20.0);
}
else if(i % 3 == 0)
{
snow_list[i].y += 2;
snow_list[i].x -= 0.005*snow_list[i].y;
}
else if(i % 7 == 0 )
{
snow_list[i].y += 2;
snow_list[i].x += 0.005*snow_list[i].y;
}
else
{
snow_list[i].y += 1.5;
}
if(snow_list[i].x + r >= stage.stageWidth)
{
snow_list[i].x = Math.random()*960;
snow_list[i].y = 1;
}
if(snow_list[i].y + r >= stage.stageHeight)
{
snow_list[i].y = 1;
}
if(snow_list[i].x <= 0)
{
snow_list[i].x = stage.stageWidth;
}
}
}
}
}
欢迎大家拍砖
42

被折叠的 条评论
为什么被折叠?



