forked from: 秒速5センチメートル
なぜかforke元では背景が出なかったので、出してみた。
挙動がおかしかったのでちょい修正。
// forked from brick's 秒速5センチメートル
// write as3 code here..
// なぜかforke元では背景が出なかったので、出してみた。
// 挙動がおかしかったのでちょい修正。
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.filters.BlurFilter;
[SWF(backgroundColor="#555f76", frameRate=30)]
public class FivecmPerSecSnow extends Sprite {
private var vx:Number;
private var vy:Number;
private var _vx:Number = 35;
private var _vy:Number = 25;
private var largeSnows:Array;
private var midSnows:Array;
private var smallSnows:Array;
private var numSnow:int = 10;
private var largeScale:Number = 1.1;
private var midScale:Number = 0.6;
private var smallScale:Number = 0.3;
public function FivecmPerSecSnow() {
init();
}
private function init():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
largeSnows = new Array();
addSnows(largeSnows, numSnow, largeScale);
midSnows = new Array();
addSnows(midSnows, numSnow, midScale);
smallSnows = new Array();
addSnows(smallSnows, 20, smallScale);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void {
moveSnow(largeSnows, largeScale);
moveSnow(midSnows, midScale);
moveSnow(smallSnows, smallScale);
}
private function addSnows(snows:Array, numSnow:int, scale:Number = 1.0)
{
for (var i:int = 0; i < numSnow; i++) {
var snow:Sprite = makeSnow(0xffffff);
addChild(snow);
snow.x = Math.random() * stage.stageWidth;
snow.y = Math.random() * stage.stageHeight;
snow.rotation = Math.atan2(_vy, _vx) * 180 / Math.PI + 90;
snow.scaleX = scale;
snow.scaleY = scale;
snows.push(snow);
var blur:BlurFilter = new BlurFilter(5, 5, 3);
snow.filters = [blur];
}
}
private function moveSnow(snows:Array, scale:Number = 1):void {
for (var i:int = 0; i < snows.length; i++) {
var snow:Sprite = snows[i];
vx = Math.random() * _vx + _vx / 2;
vy = Math.random() * _vy + _vy / 2;
snow.x += vx * scale;
snow.y += vy * scale;
snow.rotation = Math.atan2(vy, vx) * 180 / Math.PI + 90;
if (snow.x > stage.stageWidth || snow.y > stage.stageHeight) {
if (Math.random() > 0.5) {
snow.x = 0;
snow.y = Math.random() * stage.stageHeight;
} else {
snow.x = Math.random() * stage.stageWidth;
snow.y = 0;
}
}
}
}
private function makeSnow(color:uint):Sprite {
var sp:Sprite = new Sprite();
sp.graphics.lineStyle(1, color);
sp.graphics.beginFill(color);
sp.graphics.moveTo(0, 0);
sp.graphics.lineTo(5, 0);
sp.graphics.lineTo(5, 30);
sp.graphics.lineTo(0, 30);
sp.graphics.lineTo(0, 0);
sp.graphics.endFill();
return sp;
}
}
}