Math.atan2 on 2012-8-28
画面上にマウスを乗せてみてください。
/**
* Copyright Seiya.Kai ( http://wonderfl.net/user/Seiya.Kai )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kfv2
*/
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;
public function Main()
{
for (var i:int = 0; i < 100; i++)
{
var sq:Sprite = new Squid(Math.random()*WIDTH,Math.random()*HEIGHT);
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)
{
s.x = _x;
s.y = _y;
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;
}
}