drawpoly.as

来自「AS3的画图功能一些源码」· AS 代码 · 共 37 行

AS
37
字号
/*-------------------------------------------------------------	mc.drawPoly is a method for creating regular	polygons. Negative values for sides will draw the	polygon in the reverse direction, which allows for	creating knock-outs in masks.-------------------------------------------------------------*/MovieClip.prototype.drawPoly = function(x, y, sides, radius, angle) {	// ==============	// mc.drawPoly() - by Ric Ewing (ric@formequalsfunction.com) - version 1.4 - 4.7.2002	// 	// x, y = center of polygon	// sides = number of sides (Math.abs(sides) must be > 2)	// radius = radius of the points of the polygon from the center	// angle = [optional] starting angle in degrees. (defaults to 0)	// ==============	if (arguments.length<4) {		return;	}	// convert sides to positive value	var count = Math.abs(sides);	// check that count is sufficient to build polygon	if (count>2) {		// init vars		var step, start, n, dx, dy;		// calculate span of sides		step = (Math.PI*2)/sides;		// calculate starting angle in radians		start = (angle/180)*Math.PI;		this.moveTo(x+(Math.cos(start)*radius), y-(Math.sin(start)*radius));		// draw the polygon		for (n=1; n<=count; n++) {			dx = x+Math.cos(start+(step*n))*radius;			dy = y-Math.sin(start+(step*n))*radius;			this.lineTo(dx, dy);		}	}};

⌨️ 快捷键说明

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