Last active
June 29, 2017 14:04
-
-
Save diegogangl/19d71ce279621eea0d5d42bf74d6afbf to your computer and use it in GitHub Desktop.
A simple function to get indices around an index "i" in a diamond shape. Returns a list of indices usable for a 2D grid in a flat list.
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
def get_indices_diamond(i, radius, side): | |
""" Get indices around i in a diamond shape """ | |
indices = [] | |
indices += [i + j for j in range(radius + 1)] | |
indices += [i - j for j in range(1, radius + 1)] | |
for step in range(1, radius): | |
indices += [i + side * step + j for j in range(radius - (step - 1))] | |
indices += [i + side * step - j for j in range(radius - (step - 1))] | |
indices += [i-side * step + j for j in range(radius - (step - 1))] | |
indices += [i-side * step - j for j in range(radius - (step - 1))] | |
return [int(index) for index in indices] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment