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

Newton balls (forked from: flash on 2009-2-27)

// forked from awef's flash on 2009-2-27
package
{
    import flash.display.*;
    import flash.events.*;
    
    public class main extends Sprite
    {
        private var obj:Array = new Array();
        
        private function add(o:DisplayObject):void
        {
            obj.push(o);
            stage.addChild(o);
        }
        
        function main()
        {
            for(var ix:uint = 10; ix < 35; ix++)
            {
                for(var iy:uint = 10; iy < 35; iy++)
                {
                    add(new eyeball(ix * 10 + 5, iy * 10 + 5, 4, 20));
                }
            }
            
            stage.addEventListener(Event.ENTER_FRAME, frame);
        }
        
        private function frame(e:Event):void
        {
            for(var i:String in obj)
            {
                 obj[i].run();
            }
        }
    }
}

import flash.display.*;
import flash.geom.Point;

class eyeball extends Shape
{
    private var r:uint;
    private var s:uint;
    private var c:uint = Math.round(Math.random() * 255 * 255 * 255);
    
    function eyeball(arg_x:uint, arg_y:uint, arg_r:uint, arg_s:uint)
    {
        x = arg_x;
        y = arg_y;
        r = arg_r;
        s = arg_s;
        
        graphics.beginFill(c, 0.75);
        graphics.drawCircle(0, 0, r);
        graphics.endFill();
    }

    private var vx:Number = 0, vy:Number = 0;

    public function run():void
    {
        // how about some Newtonian gravity?
        var dist:Number = 1 + Math.sqrt ((x - stage.mouseX) * (x - stage.mouseX)
            + (y - stage.mouseY) * (y - stage.mouseY));
        var d3:Number = dist * dist * dist;
        var ax:Number = 8 * (stage.mouseX - x) / d3; vx += ax;
        var ay:Number = 8 * (stage.mouseY - y) / d3; vy += ay;

        // with some stellar gas friction :)
        x += vx; vx *= 0.98;
        y += vy; vy *= 0.98;
    }
}