2010-05-19 65 views
0

我试图用线构建一个圆。每条线从圆的中心开始,与圆的半径一样长。使用循环以及正弦和余弦波,我可以使用正弦和余弦构建圆以标记lineTo参数的坐标。ActionScript lineStyle填充一个圆的厚度

我的问题是线条粗细参数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这样的浮点数是否是有效厚度。

+0

我想我明白你想达到什么样的,但我真的不明白为什么* *? (我只是好奇) – grapefrukt 2010-05-19 12:25:37

+0

它是这样我可以访问每行的颜色值 – TheDarkIn1978 2010-05-19 12:35:48

回答

1

我建议把他们拉楔子而不是行,复制并粘贴到一个新的FLA,看看我的意思是:

VAR nRadians:号码;

var nRadius:Number = 100;

var nX:Number;

var nY:Number;

var previousX:Number = nRadius;

var previousY:Number = 0;

//这是对我来说很有意义,但它仍然造成一定的差距

VAR lineThickness:数= 1 +(((nRadius * 2)* Math.PI) - 360)/ 359;

为(VAR我:= 0;我< 360;我++){

//转换度为弧度。 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; 

}