Last active
November 7, 2016 02:24
-
-
Save CosineP/959912c447c5e7a203dc2d5775e02be3 to your computer and use it in GitHub Desktop.
This file contains 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
// Requires Math.floor if you don't have it already | |
import java.lang.Math.floor; | |
// [...] | |
// Loop in a diamond (that will be converted to zig-zag) | |
for (int y = -1; y <= 1; y++) | |
{ | |
// X side of the diamond | |
for (int x = -1; x <= 1; x++) | |
{ | |
// if this is the node we are on then skip it | |
if ((x==0) && (y==0)) | |
{ | |
continue; | |
} | |
// Convert diamond-x to zig-zag x (relatively) - a rotation and offset for odd rows | |
int dx = Math.floor((x - y + (current.y&1)) / 2); | |
int dy = x + y; | |
int xp = dx + current.x; | |
int yp = dy + current.y; | |
// The rest | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment