forked from: manyball

by bradsedito
♥0 | Line 51 | Modified 2014-07-02 22:42:39 | MIT License
play

ActionScript3 source code

/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ngf0
 */

// forked from Yohei.Hino's manyball
package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    
    [SWF(backgroundColor=0x000000, width=465, height=465)]
    public class manyball extends Sprite
    {
        private var ball:Array=[];
        public function manyball()
        {
            stage.scaleMode=StageScaleMode.NO_SCALE;
            stage.align=StageAlign.TOP_LEFT;
            
            for(var i:int=0;i<100;i++){
                var b:Ball=new Ball(Math.random()*0xFFFFFF);
                b.x=stage.stageWidth*Math.random();
                b.y=stage.stageWidth*Math.random();
                ball.push(b);
                addChild(ball[i]);
            }
            addEventListener(Event.ENTER_FRAME,onEnterFrame);
        }
        private function onEnterFrame(e:Event):void{
            for(var i:int=0;i<100;i++){
                ball[i].y+=ball[i].vy;
                ball[i].x+=ball[i].vx;
                //下まで行ったら上に行く
                //
                if(ball[i].y > stage.stageHeight+ball[i].r)
                    ball[i].y=0-ball[i].r;
                if(ball[i].y<0-ball[i].r)
                    ball[i].y=stage.stageHeight+ball[i].r;
                if(ball[i].x > stage.stageWidth+ball[i].r)
                    ball[i].x=0-ball[i].r;
                if(ball[i].x<0-ball[i].r)
                    ball[i].x=stage.stageWidth+ball[i].r;
            }
        }
    }
}
import flash.display.Sprite;

class Ball extends Sprite{
    public var r:int;
    public var vy:Number=(Math.random()-0.5)*10;
    public var vx:Number=(Math.random()-0.5)*10;
    public function Ball(color:Number){
        r=30;
        graphics.beginFill(color);
        graphics.drawCircle(0,0,r*Math.random());
        graphics.endFill();
    }
}