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

Mouse Move Circle

Get Adobe Flash player
by gussy 22 May 2012
    Embed
package {
    import flash.geom.Point;
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    
    public class Main extends Sprite {
       
        private var dots:Vector.<Dot> = new Vector.<Dot>;
        
        public function Main()
        {
            Size.WIDTH = stage.stageWidth;
            Size.HEIGHT = stage.stageHeight;
            
            create();
            
            stage.addEventListener(Event.ENTER_FRAME,render);
        }
        
        private function create():void
        {
            var dx:int = 0;
            var dy:int = 0;
            for(var i:int = 0; i < Size.max; i++)
            {
                var dot:Dot = new Dot();
                addChild(dot);
                dot.x = 5 + dx * 5;
                dot.y = dy * 5;
                dot.init(dot.x,dot.y);
                dots[i] = dot;
                dx++;
                if(dx >= 90)
                {
                    dy++;
                    dx = 0;
                }
            }
        }

        private function render(e:Event):void
        {
            for(var i:int = 0; i < dots.length; i++)
            {
                var dot:Dot = dots[i];
                dot.color();
                var angle:Number = Math.atan2(dot.x - mouseY, dot.x - mouseX);
                var distance:Number = Math.sqrt(Math.pow(mouseX - dot.x,2) + Math.pow(mouseY - dot.y,2));
                var circle:Number = Size.radius / distance;
                if(distance < 100){
                    dot.x += circle*Math.cos(angle) + (dot.tx - dot.x)*Size.acceleration;
                    dot.y += circle*Math.sin(angle) + (dot.ty - dot.y)*Size.acceleration;
                }else{
                    dot.x += (dot.tx - dot.x)*Size.deceleration;
                    dot.y += (dot.ty - dot.y)*Size.deceleration;
                    if (Math.abs(dot.tx - dot.x) < 0.5 && Math.abs(dot.ty - dot.y) < 0.5) {
                        dot.x = dot.tx;
                        dot.y = dot.ty;
                    }
                }
            }
        }
        
    }
}

import flash.display.Graphics;
import flash.display.Sprite;
import flash.geom.ColorTransform;
class Dot extends Sprite
{
    public var id:Number;
    public var tx:Number;
    public var ty:Number;
    public function Dot()
    {
        var g:Graphics = this.graphics;
        g.beginFill(0x0000FF);
        g.drawCircle(0,0,1);
        g.endFill();
    }
    
    public function init(px:Number,py:Number):void
    {
        tx = px;
        ty = py;
    }
    
    public function color():void
    {
        var distance:Number = Math.sqrt(Math.pow(tx - x,2) + Math.pow(ty - y,2));
        var dx:Number = distance / 40;
        var mc:Number = 255*dx;
        var nc:Number = 255 - 255*dx;
        var trans:ColorTransform = new ColorTransform(1,1,1,1,nc,mc,nc,0);
        transform.colorTransform = trans;
    }
}


class Size
{
    public function Size(){}
    public static var WIDTH:Number;
    public static var HEIGHT:Number
    
    public static const radius:int = 100;    
    public static const max:int = 9000;
    
    public static const acceleration:Number = 0.01;
    public static const deceleration:Number = 0.1;
}