Pointの練習
Point
/**
* Copyright argon ( http://wonderfl.net/user/argon )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/s4lo
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
/**
* ...
* @author I am Afro Boy ヾ(。`Д´。)ノ
*/
public class Main extends Sprite
{
private var maru:Draw;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
maru = new Draw();
addChild(maru);
var pt:Point = new Point(300, 100);
var angle:Number = Math.atan2(pt.y, pt.x);
trace(angle * 180 / Math.PI);
graphics.lineStyle(3, 0x000000);
graphics.moveTo(0, 0);
graphics.lineTo(pt.x, pt.y);
var vec1:Point = new Point(30, 20);
var vec2:Point = new Point(5, 5);
var vec3:Point = vec1.add(vec2);
var vec4:Point = vec2.subtract(vec1);
var d:Number = Point.distance(vec1, vec2);
trace(vec3, vec4, d);
/*graphics.beginFill(0x000000);
graphics.drawCircle(vec1.x, vec1.y, 5);
graphics.endFill();*/
graphics.beginFill(0x000000);
graphics.drawCircle(pt.x, pt.y,5);
graphics.endFill();
var pt1:Point = new Point(300, 50);
var pt2:Point = new Point(450, 200);
var pt3:Point = new Point(100, 450);
graphics.lineStyle(3, 0x000000);
graphics.moveTo(pt1.x, pt1.y);
graphics.lineTo(pt2.x, pt2.y);
graphics.lineTo(pt3.x, pt3.y);
graphics.drawCircle(pt1.x, pt1.y, 5);
graphics.drawCircle(pt2.x, pt2.y, 5);
graphics.drawCircle(pt3.x, pt3.y, 5);
graphics.endFill();
maru.x = pt.x; maru.y = pt.y;
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
private function onEnterFrameHandler(e:Event):void
{
maru.rotation += .5;
}
}
}
import flash.display.MovieClip;
import flash.display.Sprite;
/**
* ...
* @author I am Afro Boy ヾ(。`Д´。)ノ
*/
class Draw extends MovieClip
{
private var sp:Sprite;
public function Draw()
{
sp = new Sprite();
sp.graphics.lineStyle(3, 0x000000);
sp.graphics.moveTo(0, 0);
sp.graphics.lineTo(10, 0);
sp.graphics.drawCircle(0, 0, 10);
sp.graphics.endFill();
addChild(sp);
}
}