0

我正在尝试使用线条建立一个圆圈。每条线都从圆的中心开始,与圆的半径一样长。使用循环以及正弦波和余弦波,我可以使用正弦波和余弦来构建圆来标记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 的厚度。

我担心的是lineStyle厚度参数是 a Number,但似乎只取 0 到 255 之间的值,所以我不确定像 1.354 这样的浮点数是否是有效的厚度。

4

1 回答 1

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;

}

于 2010-05-19T13:16:17.420 回答