运用for循环画五角星(多角星):
/***
* 多角星
* @param vertex 顶点 角的个数
* @param radius 半径
* @param color 填充颜色
***/
//方法:
star(12);
function star(vertex:int=5,radius:int=100,color:uint=0xff0000)
{
if (vertex>=2)
{
//初始点
graphics.moveTo(radius,0);
//填充颜色;
graphics.beginFill(color);
//for循环画线条 vertex*2需要经过的顶点数;
for (var i:int = 1; i < vertex*2; i++)
{
//半径
var radius2:Number = radius;
//求模,余数不等于0,这里其实就是奇、偶数的判断
if (i % 2 !=0)
{
//i为奇数的时候半径减半
radius2 = radius / 2;
}
//当前角度
var angle:Number = Math.PI * 2 / (vertex * 2) * i;
//点的坐标(通过角度与半径计算每一个顶点的坐标)
graphics.lineTo(Math.cos(angle) * radius2,Math.sin(angle) * radius2);
}
//结束画图
this.graphics.endFill();
//移动图形坐标;
x = y = radius;
//旋转图形
//rotation = -90;
}
}
浙公网安备 33010602011771号