Last active
October 17, 2017 01:42
-
-
Save prehnRA/2bd7dd118b358cd4ec7e74490fb6b009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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