Skip to content

Instantly share code, notes, and snippets.

@prehnRA
Last active October 17, 2017 01:42
Show Gist options
  • Save prehnRA/2bd7dd118b358cd4ec7e74490fb6b009 to your computer and use it in GitHub Desktop.
Save prehnRA/2bd7dd118b358cd4ec7e74490fb6b009 to your computer and use it in GitHub Desktop.
[16][15][14][13][12]
[17][ 4][ 3][ 2][11]
[18][ 5][ 0][ 1][10]
[19][ 6][ 7][ 8][ 9]
[20][21][22][23][24]
Vector3 Spiral(int n)
{
float k = Mathf.Ceil((Mathf.Sqrt(n) — 1.0f) / 2.0f);
float t = 2.0f * k;
float m = (t + 1f) * (t + 1f);
if (n >= m — t)
{
return new Vector3(k — (m — n), 0f, -k);
}
else
{
m = m — t;
}
if (n >= m — t)
{
return new Vector3(-k, 0f, -k + (m — n));
}
else
{
m = m — t;
}
if (n >= m — t)
{
return new Vector3(-k + (m-n), 0f, k);
}
else
{
return new Vector3(k, 0f, k — (m — n — t));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment