forked from: 雪が降る
雪を降らせる。
必要になったので調べて作った。
// forked from sake's 雪が降る
/*
雪を降らせる。
必要になったので調べて作った。
*/
package
{
import flash.display.Sprite;
[SWF(width="465", height="465", backgroundColor="0x405060", frameRate="60")]
public class snows extends Sprite
{
public function snows()
{
for (var k:int = 0; k < 1000; k++)
addChild(new snow(stage.stageWidth, stage.stageHeight));
}
}
}
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
class snow extends Sprite
{
private var i:Number;
private var k:Number;
private var theta:Number;
private var movieHeight:Number;
private var movieWidth:Number;
private var x0:Number;
private var y0:Number;
private var y1:Number;
private static const margin:Number = 5;
public function snow(w:Number, h:Number)
{
movieHeight = h + margin * 2;
movieWidth = w + margin * 2;
x0 = -margin;
y0 = -margin;
y1 = h + margin;
i = Math.random() * 1 + 0.5;
k = 0.02;
theta = Math.random() * Math.PI - Math.PI;
graphics.beginFill(0xffffff, 1);
graphics.drawCircle(0, 0, 3);
graphics.endFill();
filters=[new BlurFilter()];
var a:Number = Math.random();
scaleX = scaleY = a * 1.5 + 0.1;
alpha = a * 0.5 + Math.random() * 0.4 + 0.1;
x = x0 + Math.random() * movieWidth;
y = y0 + Math.random() * movieHeight;
addEventListener(Event.ENTER_FRAME, onFrame);
}
private function onFrame(e:Event):void
{
theta += k;
x -= Math.cos(theta);
y += i;
if (y >= y1)
y -= movieHeight;
if (x < x0) {
x += movieWidth;
} else if (x >= movieWidth) {
x -= movieWidth;
}
}
}