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

just playin'

Get Adobe Flash player
by bradsedito 21 Dec 2011
    Embed
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ty2kp
 */

// forked from lizhi's flash on 2011-12-20




package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
     import com.greensock.*;
     import com.greensock.easing.*;
     import net.hires.debug.Stats;

    [SWF(width = "465", height = "465", frameRate = "90")]

    public class Main extends Sprite
    {
        private var ais:Array = [];
        private var target:AI = new AI;
        
        public function Main():void
        {
            if (stage)
                init();
            else
                addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            var c:int = 10;
            while (c-- > 0)
            {
                var ai:AI = new AI;
                ai.x = stage.stageWidth * Math.random();
                ai.y = stage.stageHeight * Math.random();
                ais.push(ai);
            }
            addEventListener(Event.ENTER_FRAME, enterFrame);
            target.x = stage.stageWidth * Math.random();
            target.y = stage.stageHeight * Math.random();
            
            addChild(new Stats);
        }
        
        private function enterFrame(e:Event):void
        {
            var dx:Number = mouseX - target.x;
            var dy:Number = mouseY - target.y;
            var a:Number = Math.atan2(dy, dx);
            var speed:Number = 2;
            if (Math.sqrt(dx * dx + dy * dy) > speed)
            {
                TweenMax.to(target, 1, {x:mouseX,y:mouseY,ease:Quad.easeOut});                
                var sx:Number = speed * Math.cos(a);
                var sy:Number = speed * Math.sin(a);
                //target.x += sx;
                //target.y += sy;
            }
            else
            {
                target.x = mouseX;
                target.y = mouseY;
            }
            
            graphics.clear();
            graphics.lineStyle(0);
            for each (var ai:AI in ais)
            {
                dx = target.x - ai.x;
                dy = target.y - ai.y;
                a = Math.atan2(dy, dx);
                speed = 1;
                var tx:Number = ai.x;
                var ty:Number = ai.y;
                if (Math.sqrt(dx*dx+dy*dy)>speed) 
                {
                    TweenMax.to(target, 3, {x:mouseX,y:mouseY,ease:Quad.easeOut});                
                    sx = speed * Math.cos(a);
                    sy = speed * Math.sin(a);
                    tx += sx;
                    ty += sy;
                }else {
                    tx = target.x;
                    ty = target.y;
                }
                
                var tooClose:Boolean = false;
                
                for each(var ai2:AI in ais) {
                    if(ai2!=ai){
                        var dx2:Number = ai2.x - tx;
                        var dy2:Number = ai2.y - ty;
                        if (Math.sqrt(dx2*dx2+dy2*dy2)<20) {
                            tooClose = true;
                            break;
                        }
                    }
                }
                if (!tooClose) {
                    ai.x = tx;
                    ai.y = ty;
                }
                
                graphics.drawCircle(ai.x, ai.y, 10);
            }
            graphics.lineStyle(0, 0xff0000);
            graphics.drawCircle(target.x, target.y, 10);
        }
    
    }

}
import flash.geom.Point;
    /**
     * ...
     * @author lizhi
     */
    class AI extends Point
    {
        public function AI() 
        {
            
        }
        
    }