Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahtzee/37602da7a90a2737cff84c56caa58717 to your computer and use it in GitHub Desktop.
Save jahtzee/37602da7a90a2737cff84c56caa58717 to your computer and use it in GitHub Desktop.
Representing rotatable two-dimensional structures with 1d arrays
x
0 1 2 3
_ _ _ _ _ _
0|0 1 2 3
y 1|4 5 6 7
2|8 9 10 11
3|12 13 14 15
i = index
w = width
0°) i=wy + x
90°) i=w(w-1) + y - wx
180°) i= w^2 - 1 - wy - x
270°) i= w - 1 - y +wx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment