Instantly share code, notes, and snippets.

Embed
What would you like to do?
Used when generating images from regular expressions (http://jackm.co.uk/posts/2014/03/25/using-regular-expressions-to-generate-images/)
def get_region_identifier(x, y, resolution):
region_identifier = ""
for i in range(resolution):
r = int((y % 2**(resolution-i)) / 2**(resolution-1-i))
c = int((x % 2**(resolution-i)) / 2**(resolution-1-i))
region_identifier += chr(int((1-r)*c + r*(3-c)) + 48)
return region_identifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment