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

DeflectRandom

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

// forked from fakestar0826's CircloidRandom
// forked from fakestar0826's Brown
// forked from fakestar0826's flash on 2011-2-24
package {
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite 
    {
        private var numDots:int = 1000;
        private var friction:Number = 0.95;
        private var dots:Array;
        private var maxRadius:Number = 50;
        private var it:int = 6;
        public function FlashTest() 
        {
            graphics.lineStyle(0, 0, 0.5);
            dots = [];
            for(var i:int = 0;i < numDots;i++)
            {
                var d:Ball = new Ball(1);
                var xpos:Number = 0;
                for(var j:int = 0; j < it;j++)
                {
                    xpos += Math.random() * stage.stageWidth;
                }

                d.x = xpos / it;
                d.y = stage.stageHeight / 2 + Math.random() * 50 - 25;
                d.vx = 0;
                d.vy = 0;
                addChild(d);
                dots[i] = d;
            }

            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(e:Event):void
        {
            for(var i:int = 0;i < numDots;i++)
            {
                var d:Ball = dots[i];
                
                d.vx += Math.random() * 0.2 - 0.1;
                d.vy += Math.random() * 0.2 - 0.1;
                d.x += d.vx;
                d.y += d.vy;
                d.vx *= friction;
                d.vy *= friction;
                
                if(d.x > stage.stageWidth)
                {
                    d.x = 0;
                }
                else if(d.x < 0)
                {
                    d.x = stage.stageWidth;
                }
                
                if(d.y > stage.stageHeight)
                {
                    d.y = 0;
                }
                else if(d.y < 0)
                {
                    d.y = stage.stageHeight;
                }
            }
        }

    }
}
import flash.display.Sprite;

class Ball extends Sprite
{
    public var vx:Number = 0;
    public var vy:Number = 0;
    public function Ball(r:Number = 10)
    {
        graphics.beginFill(0xFF0000);
        graphics.drawCircle(0, 0, r);
        graphics.endFill();
    }

}