我正在尝试使用线条构建一个圆圈。每条线从圆的中心开始,并且与圆的半径一样长。使用循环以及正弦和余弦波,我可以使用正弦和余数来构建圆,以标记lineTo
参数的坐标。
我的问题在于lineStyle
的线宽参数。我希望线条的两端完美匹配,无论圆周长多大,但我无法找到适合线条粗细的方法。
//this is what makes sense to me, but it still creates some gaps
lineThickness = 1 + (((nRadius * 2) * Math.PI) - 360) / 359;
for(var i:int = 0; i < 360; i++)
{
// Convert the degree to radians.
nRadians = i * (Math.PI / 180);
// Calculate the coordinate in which the line should be drawn to.
nX = nRadius * Math.cos(nRadians);
nY = nRadius * Math.sin(nRadians);
// Create and drawn the line.
graphics.lineStyle(lineThickness, 0, 1, false, LineScaleMode.NORMAL, CapsStyle.NONE);
graphics.moveTo(0, 0);
graphics.lineTo(nX, nY);
}
为了使线条的末端在圆周上相遇,没有任何间隙,我需要加宽线条以填充剩余的空间。对我来说有意义但是不起作用的是从圆周中减去360,然后将该数字除以线之间的空槽数量(即359)并将该数字加上1的厚度。 / p>
关于我的是lineStyle
厚度参数是Number
,但似乎只取0到255之间的值,所以我不确定像1.354这样的浮点数是不是有效厚度。
答案 0 :(得分:1)
我建议将它们绘制成楔形而不是线条,将其复制并粘贴到新的FLA中以查看我的意思:
var nRadians : Number;
var nRadius : Number = 100;
var nX : Number;
var nY : Number;
var previousX : Number = nRadius;
var previousY : Number = 0;
//this is what makes sense to me, but it still creates some gaps
var lineThickness : Number = 1 + ( ( ( nRadius * 2 ) * Math.PI ) - 360 ) / 359;
for( var i : int = 0; i < 360; i++ )
{
// Convert the degree to radians.
nRadians = i * ( Math.PI / 180 );
// Calculate the coordinate in which the line should be drawn to.
nX = nRadius * Math.cos( nRadians );
nY = nRadius * Math.sin( nRadians );
// Create and drawn the line.
graphics.beginFill( Math.random() * 0xFFFFFF );
graphics.moveTo( 0, 0 );
graphics.lineTo( previousX, previousY );
graphics.lineTo( nX, nY );
graphics.lineTo( 0, 0 );
graphics.endFill();
previousX = nX;
previousY = nY;
}