ActionScript 3 动态绘制螺旋

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 动态绘制螺旋相关的知识,希望对你有一定的参考价值。

//
//
// centerX-- X origin of the spiral.
// centerY-- Y origin of the spiral.
// radius--- Distance from origin to outer arm.
// sides---- Number of points or sides along the spiral's arm.
// coils---- Number of coils or full rotations. (Positive numbers spin clockwise, negative numbers spin counter-clockwise)
// rotation- Overall rotation of the spiral. ('0'=no rotation, '1'=360 degrees, '180/360'=180 degrees)
//
function spiral(centerX, centerY, radius, sides, coils, rotation){
	//
	with(this){// Draw within the clip calling the function.
		//
		// Start at the center.
		moveTo(centerX, centerY);
		//
		// How far to step away from center for each side.
		var awayStep = radius/sides;
		//
		// How far to rotate around center for each side.
		var aroundStep = coils/sides;// 0 to 1 based.
		//
		// Convert aroundStep to radians.
		var aroundRadians = aroundStep * 2 * Math.PI;
		//
		// Convert rotation to radians.
		rotation *= 2 * Math.PI;
		//
		// For every side, step around and away from center.
		for(var i=1; i<=sides; i++){
			//
			// How far away from center
			var away = i * awayStep;
			//
			// How far around the center.
			var around = i * aroundRadians + rotation;
			//
			// Convert 'around' and 'away' to X and Y.
			var x = centerX + Math.cos(around) * away;
			var y = centerY + Math.sin(around) * away;
			//
			// Now that you know it, do it.
			lineTo(x, y);
		}
	}
}
//
//
//
// spiral(centerX, centerY, radius, sides, coils, rotation).
//
// Big center spirals.
lineStyle(27, 0x0000FF);// Blue.
spiral(250, 210, 200, 200, 4, 0);
lineStyle(27, 0xFF0000);// Red.
spiral(250, 210, 127, 200, 2.5, .5);
//
// Small corner spirals.
lineStyle(4, 0xFF00FF);//            Magenta.
spiral(50, 50, 50, 200, 6, 0);//       Big.
spiral(125, 50, 25, 200, 2, .5);//     Small.
lineStyle(4, 0x00FFFF);//            Cyan.
spiral(450, 50, 50, 200, -6, .5);//    Big.
spiral(375, 50, 25, 200, -2, 0);//     Small.
lineStyle(4, 0xFFFF00);//            Yellow.
spiral(50, 350, 50, 200, -4, 0);//     Big.
spiral(125, 350, 25, 200, -3, .5);//   Small.
lineStyle(4, 0x00FF00);//            Green.
spiral(450, 350, 50, 200, 4, .5);//    Big.
spiral(375, 350, 25, 200, 3, 0);//     Small.
//
//

以上是关于ActionScript 3 动态绘制螺旋的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 动态绘制圆圈

ActionScript 3 Flash画廊效果中的AS3 3D旋转螺旋

ActionScript 3 在Actionscript中绘制缩放对象

ActionScript 3 从下到上绘制条形图补间

ActionScript 3 绘制像素箭头

ActionScript 3 绘制线性渐变