DrawPathSample

by HaraMakoto
♥0 | Line 41 | Modified 2009-08-16 21:45:28 | MIT License
play

ActionScript3 source code

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

package {
	import __AS3__.vec.Vector;
	
	import flash.display.GraphicsPathWinding;
	import flash.display.Sprite;
	
	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
	public class DrawpathSample extends Sprite
	{
		private var shapeAr:Array=[{x:123.414,y:159.386},{x:128.88,y:158.936},{x:141.85,y:156.729},{x:157.163,y:151.474},{x:169.659,y:141.888},{x:176.103,y:127.418},{x:176.22,y:110.486},{x:169.308,y:94.26},{x:154.662,y:81.898},{x:131.54,y:75.336},{x:103.729,y:74.399},{x:77.327,y:79.085},{x:58.425,y:89.396},{x:49.737,y:103.713},{x:47.958,y:118.612},{x:50.166,y:131.404},{x:53.428,y:139.391},{x:57.958,y:145.19},{x:66.236,y:152.045},{x:78.736,y:158.196},{x:95.919,y:161.888},{x:116.443,y:162.667},{x:137.316,y:163.446},{x:156.55,y:167.511},{x:172.156,y:178.134},{x:182.39,y:195.181},{x:186.531,y:214.221},{x:184.107,y:232.089},{x:174.658,y:245.622},{x:160.93,y:255.113},{x:145.445,y:262.493},{x:127.382,y:267.063},{x:105.919,y:268.117},{x:84.555,y:265.581},{x:67.173,y:259.997},{x:53.545,y:251.601},{x:43.428,y:240.624},{x:38.02,y:226.582},{x:37.648,y:210.782},{x:40.792,y:196.158},{x:45.93,y:185.632},{x:52.766,y:178.467},{x:61.239,y:172.355},{x:70.179,y:167.885},{x:78.421,y:165.636}];
		public function DrawpathSample()
		{
			//drawWithLineTo();
			drawWithDrawPath();
		}
		
		private function drawWithLineTo():void
		{
			var i:int;
			var len:int=shapeAr.length;
			this.graphics.lineStyle(1,0xFFFFFF);
			this.graphics.moveTo(shapeAr[0].x, shapeAr[0].y);
			for(i=1;i<len;i++) {
				this.graphics.lineTo(shapeAr[i].x, shapeAr[i].y);
			}
		}
		
		private function drawWithDrawPath():void
		{
			var i:int;
			var len:int=shapeAr.length;
			var _commands:Vector.<int> = new Vector.<int>(len, true);
			var _cood:Vector.<Number> = new Vector.<Number>(len*2, true);
			_commands[0] = 1;
			_cood[0] = shapeAr[0].x;
			_cood[1] = shapeAr[0].y;
			for(i=1;i<len;i++) {
				_commands[i] = 2;
				_cood[i*2] = shapeAr[i].x;
				_cood[i*2+1] = shapeAr[i].y;
			}
			this.graphics.lineStyle(1,0xFFFFFF);
			this.graphics.drawPath(_commands, _cood, GraphicsPathWinding.NON_ZERO);
		}	
	}
}