forked from: Math.atan2 on 2012-8-28

by bradsedito forked from Math.atan2 on 2012-8-28 (diff: 15)
♥0 | Line 48 | Modified 2012-09-01 04:15:09 | MIT License
play

ActionScript3 source code

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






package
{
    import flash.display.Sprite;
    
    [SWF(width="600",height="600",frameRate="60")]
    public class Main extends Sprite
    {
        private const WIDTH:Number = 600;
        private const HEIGHT:Number = 600;
        private const DEPTH:Number = 500;
        
        public function Main()
        {
            for (var i:int = 0; i < 50; i++) 
            {
                //var sq:Sprite = new Squid(Math.random()*WIDTH,Math.random()*HEIGHT);
                var sq:Sprite = new Squid(Math.random()*WIDTH,Math.random()*HEIGHT,Math.random()*DEPTH);
                stage.addChild(sq);
            }
        }
    }
}

 

import flash.display.Sprite;
import flash.events.Event;
class Squid extends Sprite
{
    private var s:Sprite = new Sprite();
    
    public function Squid(_x:Number,_y:Number,_z:Number)
    //public function Squid(_x:Number,_y:Number)
    {
        s.x = _x;
        s.y = _y;
        s.z = _z;
        s.graphics.beginFill(0x0066ff);
        s.graphics.lineStyle(6,0x0033ff);
        s.graphics.moveTo(20,0);
        s.graphics.lineTo(0,-20);
        s.graphics.lineTo(0,-10);
        s.graphics.lineTo(-30,-10);
        s.graphics.lineTo(-30,10);
        s.graphics.lineTo(0,10); 
        s.graphics.lineTo(0,20);
        s.graphics.lineTo(20,0);
        s.graphics.endFill();
        addChild(s);
        
        s.addEventListener(Event.ENTER_FRAME,onEnterFrame);
    }
    
    private function onEnterFrame(e:Event):void
    {
        s.rotation = Math.atan2(mouseY - s.y,mouseX - s.x) * 180 / Math.PI;
    } 
}