CirclesLoveLines step 1

by onedayitwillmake
ActionScript file
♥0 | Line 55 | Modified 2009-05-13 12:57:45 | MIT License
play

ActionScript3 source code

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

// ActionScript file
package
{
		
    import flash.display.Sprite;
	
	[SWF(frameRate="60", width="465", height="465", backgroundColor="#00ffcc")]
	
    public class CircleLineSegmentTest extends Sprite
    {
    	public function CircleLineSegmentTest():void
    	{
    		var a:Vector2D = new Vector2D(Math.random() * 465, Math.random() * 465);
    		var b:Vector2D = new Vector2D(Math.random() * 465, Math.random() * 465);
    		
    		var lineA:Line = new Line(a, b);
    			addChild(lineA);
    		
    	}
    	/**
    	 * Find the closest point in a linesegment given point X  
    	 * @param X	Point to test against. 
    	 * @param A LineSegment point A
    	 * @param B LineSegment point B
    	 */    	
    	public static function closestPointLineSegment(X:Vector2D, A:Vector2D, B:Vector2D):void
    	{
    	
    	}
    }
}

import flash.geom.Point;
import flash.display.Shape;

internal class Vector2D extends Point
{
	public function Vector2D(x:Number, y:Number):void
	{
		super(x,y);
	}
}

internal class Line extends Shape
{
	public var A:Vector2D, B:Vector2D; //A |----| B
	
	public var __isDirty	:Boolean = false;
	public function Line(a:Vector2D, b:Vector2D):void
	{
		A = a;
		B = b;
		
		_isDirty = true;
	}
	
	public function draw():void
	{
		resetGraphics();
		graphics.moveTo(A.x, A.y);
		graphics.lineTo(B.x, B.y);
	}
	
	public function resetGraphics():void
	{
		graphics.clear();
		graphics.lineStyle(1, 0x666666, 1);
	}
	
	public function get _isDirty():Boolean { return __isDirty };
	public function set _isDirty(value:Boolean):void
	{
		__isDirty = value;
		draw();
	}
}

Forked