Dynamic spacing around a circle

I am trying to figure out how to dynamically place numbers around a circle (similar to a dial), but dynamically, so if the number of numbers around a circle is 5 or 27, they will be correctly selected.

I found the code (below) that looked as if it could help, but I had problems with its implementation. I don’t know how I tie this back to the circle and numbers.

Any help would be greatly appreciated. Thanks

function getNPointsOnCircle( center:Point, radius:Number, n:Number = 10 ) : Array

{

var alpha:Number = Math.PI * 2 / n;
var points:Array = new Array( n );

var i:int = -1;
while( ++i < n )
{
    var theta:Number = alpha * i;
    var pointOnCircle:Point = new Point( Math.cos( theta ) * radius, Math.sin( theta ) * radius );
    points[ i ] = center.add( pointOnCircle );
}

return points;

}

+3
source share
1 answer

This code works just fine. Here's how to use it:

var center:Point = new Point(100,100);
var radius = 100;
var n = 10


var p:Array = getNPointsOnCircle( center, radius, n)


var myContainer:Sprite = new Sprite();
myContainer.graphics.lineStyle(1);

for (var k = 0; k <p.length;k++)
{
    myContainer.graphics.drawCircle(p[k].x,p[k].y,5);
}

addChild(myContainer);
+3
source

Source: https://habr.com/ru/post/1730701/


All Articles