ActionScript lineStyle 填充圆的粗细
我正在尝试用直线构建一个圆。每条线都从圆的中心开始,与圆的半径一样长。使用循环以及正弦波和余弦波,我可以使用正弦波和余弦波来构建圆来标记 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 厚度参数是一个 Number,但似乎只取 0 到 255 之间的值,所以我不确定是否是像 1.354 这样的浮点数是有效厚度。
I'm trying to build a circle using lines. Each line starts in the center of the circle and is as long as the circle's radius. Using a loop along with sine and cosign waves, I can build the circle using the sine and cosign to mark the coordinates of the lineTo
parameter.
My problem is with the line thickness parameter of lineStyle
. I would like the ends of the lines to match up perfectly, no matter how big the circumference of the circle, but i can't figure out a proper method for the line thickness.
//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);
}
To make the ends of the lines meet up at the circles circumference, without any gaps, I need to widen the lines to fill in the space that's remaining. What makes sense to me, but doesn't work, is to subtract the 360 from the circumference, then divide that number by the amount of empty slots between the lines (which is 359) and adding that number the the thickness of 1.
What's concerning me is that the lineStyle
thickness parameter is a Number
, but seems to take only values between 0 and 255, so I'm not sure if a floating point number like 1.354 is a valid thickness.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议将它们绘制为楔形而不是线条,将其复制并粘贴到新的 FLA 中以了解我的意思:
var nRadius : 数字;
var nRadius : 数字 = 100;
var nX:数字;
var nY :数字;
var previousX : 数字 = nRadius;
var previousY : 数字 = 0;
//这对我来说是有意义的,但它仍然会产生一些间隙
var lineThickness : Number = 1 + ( ( ( nRadius * 2 ) * Math.PI ) - 360 ) / 359;
for( var i : int = 0; i < 360; i++ )
{
// 将角度转换为弧度。
nRadians = i * ( Math.PI / 180 );
}
I'd suggest drawing them as wedges instead of lines, copy and paste this into a new FLA to see what I mean:
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 );
}