Created
July 15, 2012 22:34
-
-
Save KartikTalwar/3118962 to your computer and use it in GitHub Desktop.
Nearest Grid Coordinate
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 generateGrid(x, y, r=1): | |
matrix = [] | |
for dy in xrange(-r, r+1): | |
for dx in xrange(-r, r+1): | |
matrix.append((x+dx, y+dy)) | |
return matrix | |
print generateGrid(0, 1) | |
""" | |
Returns : | |
[[(-1, 0), (0, 0), (1, 0)], | |
[(-1, 1), (0, 1), (1, 1)], | |
[(-1, 2), (0, 2), (1, 2)]] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment