Here is the code I think I sort of implemented or not. More likely not.

- Code: Select all
`public Vector3[] GenerateArm(int numOfStars, int numOfArms, float rotation)`

{

Vector3[] result = new Vector3[numOfStars];

Random r = new Random();

float fArmAngle = (float)((360 / numOfArms) % 360);

float fAngularSpread = 180 / (numOfArms * 2);

for (int i = 0; i < numOfStars; i++)

{

float fR = (float)r.NextDouble() * 64.0f;

float fQ = ((float)r.NextDouble() * fAngularSpread) * 1;

float fK = 1;

float fA = ((float)r.NextDouble() % numOfArms) * fArmAngle;

float fX = fR * (float)Math.Cos((MathHelper.DegreesToRadians(fA + fR * fK + fQ)));

float fY = fR * (float)Math.Sin((MathHelper.DegreesToRadians(fA + fR * fK + fQ)));

float resultX = (float)(fX * Math.Cos(rotation) - fY * Math.Sin(rotation));

float resultY = (float)(fY * Math.Cos(rotation) - fX * Math.Sin(rotation));

result[i] = new Vector3(resultX, resultY, 1.0f);

}

return result;

I understand some but not all. I've disabled my implementation of the lines:

float fArmAngle = (float)((360 / numOfArms) % 360);

float fAngularSpread = 180 / (numOfArms * 2);

When using these lines there isn't a spiral just a nice circle. Also the code converts degrees to radians so maybe that's where my version trips up.

This is what generates using my sort of hack of the code. Which doesn't look too bad but when changing some values it either destroys the spiral or makes a nice circle.

HTML5 Demo

And the capx. You'll need the Canvas Plugin to have a play around.

I wasn't really planning to use it for anything (or am I?) other than a learning exercise and I love stuff like this.

If anyone does have a play and improves it just post it here and if possible explain my stupidity in the implementation of code or maths.