正多边形画法:
Code
public function SetPoints(sidenum:int, centerPoint:Point, radius:Number, RotateAngle:Number = 0):void
{
var pt:Point;
for(var i:int = 0; i < sidenum; i++)
{
pt = new Point;
pt.x = centerPoint.x + radius*Math.sin(i/sidenum*Math.PI*2+CPolygon.AngleToRadian(RotateAngle));
pt.y = centerPoint.y + radius*Math.cos(i/sidenum*Math.PI*2+CPolygon.AngleToRadian(RotateAngle));
m_PointsArray.push(pt);
}
}
public function DrawOn(canvas:Sprite):void
{
canvas.graphics.moveTo(m_PointsArray[i].x, m_PointsArray[i].y);
for(var i:int = 0; i < m_PointsArray.length; i++)
{
canvas.graphics.lineTo(m_PointsArray[(i+1)%m_PointsArray.length].x, m_PointsArray[(i+1)%m_PointsArray.length].y);
}
}
正六边形网格画法:
for (var i:int = 0; i < row; i++)
{
for (var j:int = 0; j< col; j++)
{
var hexagon:CPolygon = new CPolygon(6, new Point(offsetX+Math.cos(Math.PI/6)*r*2*j+(i%2)*Math.cos(Math.PI/6)*r,offsetY+Math.sin(Math.PI/6)*r*i+r*i) ,r);
gridArray[i][j] = hexagon;
gridArray[i][j].DrawOn(ca);
}
}
//offsetX,offsetY为整个网格相对于(0,0)的偏移,即第一行第一列的正六边形中心点坐标