In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

秒速5センチメートル

Get Adobe Flash player
by brick 13 Jul 2010
// write as3 code here..
package {
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    
    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() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            
            graphics.beginFill(0x555f76);
            graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            graphics.endFill();
            
            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) {
            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 = 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 = 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;
        }
        
    }
}