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

Fountain

Get Adobe Flash player
by crossisland 20 Nov 2011
    Embed
/**
 * Copyright crossisland ( http://wonderfl.net/user/crossisland )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ahok
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    
    public class Fountain extends Sprite {
        private var balls:Array;
        private var count:int = 100;
        private var gravity:Number = 0.5;
        
        public function Fountain() {
            init();
        }
        
        private function init():void {
            balls = new Array();
            for (var i:int = 0; i < count; i++) {
                var ball:Ball = new Ball(5);
                ball.x = stage.stageWidth / 2;
                ball.y = stage.stageHeight;
                ball.vx = Math.random() * 2 - 1;
                ball.vy = Math.random() * -10 - 10;
                addChild(ball);
                balls.push(ball);
            }
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(event:Event):void {
            for (var i:Number = 0; i < balls.length; i++) {
                var ball:Ball = Ball(balls[i]);
                ball.vy += gravity;
                ball.x += ball.vx;
                ball.y += ball.vy;
                if (ball.x - ball.radius > stage.stageWidth || ball.x + ball.radius < 0 || ball.y - ball.radius > stage.stageHeight || ball.y + ball.radius < 0) {
                    ball.x = stage.stageWidth / 2;
                    ball.y = stage.stageHeight;
                    ball.vx = Math.random() * 2 - 1;
                    ball.vy = Math.random() * -10 - 10;
                }
            }
        }
    }
}

import flash.display.Sprite;

class Ball extends Sprite {
    public var radius:Number;
    public var color:uint;
    public var vx:Number = 0;
    public var vy:Number = 0;
    
    public function Ball(radius:Number=40, color:uint=0x000000) {
        this.radius = radius;
        this.color = color;
        init();
    }
    
    public function init():void {
        graphics.beginFill(color);
        graphics.drawCircle(0, 0, radius);
        graphics.endFill();
    }
}