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

Coordinate Rotation The Other Way

Get Adobe Flash player
by majoraze 31 Dec 2010
    Embed
/**
 * Copyright majoraze ( http://wonderfl.net/user/majoraze )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/31L7
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    public class CoordinateRotation extends Sprite {
        
        private var balls:Array = [];
        private var vr:Number = .1;
        private var numBalls:Number = 10;
        
        public function CoordinateRotation() {
            init();
        }
        
        private function init():void {
            for (var i:int = 0; i < numBalls; i++) {
                var ball:Ball = new Ball((Math.random() * 30) + 10, Math.random() * 0xFFFFFF + 0xFF000000);
                balls.push(ball);
                addChild(ball);
                ball.x = Math.random() * stage.stageWidth;
                ball.y = Math.random() * stage.stageHeight;
            }

            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }

        private function onEnterFrame(e:Event):void {
            var angle:Number = (mouseX - stage.stageWidth/2) * .001;
            var cos:Number = Math.cos(angle);
            var sin:Number = Math.sin(angle);
            
            for (var i:int = 0; i < numBalls; i++) {
                var ball:Ball = balls[i] as Ball;
                var x1:Number = ball.x - stage.stageWidth/2;
                var y1:Number = ball.y - stage.stageHeight/2;
                var x2:Number = cos * x1 - sin * y1;
                var y2:Number = cos * y1 + sin * x1;
            
                ball.x = stage.stageWidth/2 + x2;
                ball.y = stage.stageHeight/2 + y2;
            }
        }

    }
}




//ball class

import flash.display.Sprite;

class Ball extends Sprite {
    public var radius:Number;
    private var color:uint;
    public var vx:Number = 0;
    public var vy:Number = 0;    
    
    public function Ball(radius:Number = 40, color:uint = 0xff0000) {
        this.radius = radius;
        this.color = color;
        
        init();
    }
    
    public function init():void {
        graphics.beginFill(color);
        graphics.drawCircle(0,0,radius);
        graphics.endFill()
    }
}