rotationX / rotationY

by ne_
♥0 | Line 65 | Modified 2011-11-03 22:45:35 | MIT License
play

ActionScript3 source code

/**
 * Copyright ne_ ( http://wonderfl.net/user/ne_ )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uhVj
 */

package {
    import flash.events.MouseEvent;
    import flash.display.Sprite;
    
    /**
     * ...
     * @author Nekogui
     */
    public class Main extends Sprite {
        public function Main () {
            
            var wd:int = stage.stageWidth;
            var hg:int = stage.stageHeight;
            
            addBackground(wd,hg);
            var q:Sprite = addChild(new Quadro(wd - 50, hg - 50)) as Sprite;
            q.x = wd >> 1;
            q.y = hg >> 1;
            
            q.addEventListener(MouseEvent.MOUSE_MOVE, update);
            
            
        }
        
        private function update (e:MouseEvent):void{
            var s:Sprite = Sprite(e.currentTarget);
            var ix:Number = 30/s.width;
            var iy:Number = 30/s.height;
            
            s.rotationY = -s.mouseX * ix;
            s.rotationX = s.mouseY * iy;
        }

        
        private function addBackground(w:int, h:int):void{
            var b:Sprite = new Sprite();
            b.graphics.beginFill(0);
            b.graphics.drawRect(0,0,w,h);
            b.graphics.endFill();
            addChild(b);
        }

    }    
}


import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.geom.Rectangle;

internal class Quadro extends Sprite {
    public function Quadro (w:int, h:int) {
        var data:BitmapData = new BitmapData(w, h);
        
        var _x:int, _y:int, r:int, r2:int;
        var s:Sprite = new Sprite();
        var cont:Sprite = new Sprite();
        cont.addChild(s);
        var g:Graphics = s.graphics;
        var i:int = 100;
        var rec:Rectangle;
        while (i) {
            r = 5 + (Math.random() * 25);
            r2 = r << 2;
            _x = Math.random() * (w - r2);
            _y = Math.random() * (h - r2);
            g.beginFill(uint(Math.random() * 0xFFFFFF));
            g.drawCircle(r, r, r);
            g.endFill();
            s.x = _x;
            s.y = _y;
            rec = s.getBounds(cont);
            data.draw(cont);
            g.clear();
            
            i--;
        }
        
        var b:Bitmap = new Bitmap(data);
        b.x = -b.width >> 1;
        b.y = -b.height >> 1;
        addChild(b);
    }
}