Basic Segment

by _ryotaros
♥0 | Line 44 | Modified 2010-02-07 11:34:09 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        
        public var segment:Segment;
        
        public function FlashTest() {
            init();
        }
       
        public function init():void {
        		segment = new Segment(60,20);
        		addChild(segment);
        		segment.x =stage.stageWidth/2;
        		segment.y =stage.stageHeight/2;
        }
    }
}
import flash.display.Sprite;
import flash.geom.Point;

class Segment extends Sprite {
		
		public var segmentWidth:int;
		public var segmentHeight:int;
		public var segmentColor:int;
		
		public var vx:Number = 0;
		public var vy:Number = 0;
	
		public function Segment(sWidth:int=10,sHeight:int=10,color:uint=0xff0000):void{
			segmentWidth = sWidth;
			segmentHeight = sHeight;
			segmentColor = color;
			init();	
		}
		
		public function init():void{
			
			graphics.lineStyle(0);
			graphics.beginFill(segmentColor);
			graphics.drawRoundRect(-segmentHeight / 2, -segmentHeight /2, segmentWidth + segmentHeight, segmentHeight, segmentHeight, segmentHeight);
			graphics.endFill();
			
			graphics.drawCircle(0, 0, 2);
			graphics.drawCircle(segmentWidth, 0, 2);
		}
		
		public function getPin():Point {
			var angle:Number = rotation * Math.PI / 180;
			var xPos:Number = x + Math.cos(angle) * segmentWidth;
			var yPos:Number = y + Math.sin(angle) * segmentWidth;
			return new Point(xPos, yPos);
		}
}

Forked