starshape.as

来自「《Flash AS3殿堂之路》光盘源码 学习ActionScript 3.0」· AS 代码 · 共 43 行

AS
43
字号
/*
the core logic comes from Ric Ewing's AS1 work.
*/

package org.kingda.book.display
{
	import flash.display.Shape;
	import flash.display.GradientType;

	public class StarShape extends Shape
	{
		public function StarShape(x:Number=0, y:Number=0, 
									points:int=5, innerRadius:Number=20, 
									outerRadius:Number=50, angle:Number=0, color:uint=0xff0000) {
			
			var count = Math.abs(points);
			this.graphics.lineStyle(2, 0x85DB18);
			
			//开始填色
			this.graphics.beginFill(color);
			if (count>2) {
				// init vars
				var step, halfStep, start, n, dx, dy;
				//计算两点之间距离
				step = (Math.PI*2)/points;
				halfStep = step/2;
				//起始角度
				start = (angle/180)*Math.PI;
				this.graphics.moveTo(x+(Math.cos(start)*outerRadius), y-(Math.sin(start)*outerRadius));
				//画星状图的边
				for (n=1; n<=count; n++) {
					dx = x+Math.cos(start+(step*n)-halfStep)*innerRadius;
					dy = y-Math.sin(start+(step*n)-halfStep)*innerRadius;
					this.graphics.lineTo(dx, dy);
					dx = x+Math.cos(start+(step*n))*outerRadius;
					dy = y-Math.sin(start+(step*n))*outerRadius;
					this.graphics.lineTo(dx, dy);
				}
			}
			this.graphics.endFill();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?