开发者

ActionScript lineStyle Thickness to fill a circle

I'm trying to build a circle using lines. Each li开发者_如何学JAVAne 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.


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 );

// 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;

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜