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

forked from: Math.atan2 Example

Get Adobe Flash player
by makc3d 06 Aug 2014
/**
 * Copyright makc3d ( http://wonderfl.net/user/makc3d )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/yyBv
 */

// forked from greentec's Math.atan2 Example
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    
    public class FlashTest extends Sprite {
        
        public var _bitmap:Bitmap;
        public var whiteCircles:Array = [];
        public var blackCircles:Array = [];
        public var ps:Array = [];
        
        public function FlashTest() {
            // write as3 code here..
            _bitmap = new Bitmap(new BitmapData(465, 465, false, 0x292929));
            addChild(_bitmap);
            
            for (var i:int = 0; i < 42; i++) {
                var p1:Point = new Point(
                    465/2 + 150 - 300 * Math.random(),
                    465/2 + 150 - 300 * Math.random()
                );
                var
            whiteCircle:Shape = new Shape();
            whiteCircle.graphics.beginFill(0xffffff);
            whiteCircle.graphics.drawCircle(p1.x, p1.y, 10);
            whiteCircle.graphics.endFill();
            
            addChild(whiteCircle);
            
                var
            blackCircle1:Shape = new Shape();
            blackCircle1.graphics.beginFill(0x0);
            blackCircle1.graphics.drawCircle(p1.x, p1.y, 4);
            blackCircle1.graphics.endFill();
            
            addChild(blackCircle1);
            
            ps.push(p1);
            whiteCircles.push(whiteCircle);
            blackCircles.push(blackCircle1);
            }
            
            addEventListener(Event.ENTER_FRAME, onLoop);
        }
        
        private function onLoop(e:Event):void
        {
            for (var i:int = 0; i < ps.length; i++) {
                var p1:Point = ps[i];
            var angle:Number = Math.atan2(mouseY - p1.y, mouseX - p1.x);
                var blackCircle1:Shape = blackCircles[i];
            blackCircle1.x = Math.cos(angle) * 5;
            blackCircle1.y = Math.sin(angle) * 5;
            }
        }
    }
}