Skip to content

Instantly share code, notes, and snippets.

@mattyhall
Created July 18, 2014 11:13
Show Gist options
  • Save mattyhall/93132f1bb5ec34597e0a to your computer and use it in GitHub Desktop.
Save mattyhall/93132f1bb5ec34597e0a to your computer and use it in GitHub Desktop.
import Image
# I apologise to the Python Gods. I was in a rush. This should all be one string and therefore one line!
data = '000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 000000000000000000000000001000000000000000000000000000111 000000000000000000000000000000000000000000000000000000000 000000000000111100000000000000000000001101000000000000000 000000000000000000000000000000000000000000000000000000001 001100000000000000000011001000000000000000000000000000000 000000000000000000000000000000000000000000010001000000111 100000110000100000000000000000000000000000000000000000000 000000000000000000000000000000100010011100001110100000010 000000000000000000000000000000000000000000000000000000000 000000000000000010000110000000000110000001000101010000000 000000000000000000000000000000000000000000000000000000000 010000100000000000010000000100010101000000000000000000000 000000000000000000000000000000000000000000011000100000000 000010000000001001010100000000000000000000000000000000000 000000000000000000000000000000010010000000000010000000000 101010101000000000000000000000000000000000000000000000000 000000000000000010010000000000000000000000100101010100000 000000000000000000000000000000000000000000000000000000000 001001000000000000000000000011010000010000000000000000000 000000000000000000000000000000000000000000000011000000000 000000000000001001000001000000000000000000000000000000000 000000000000000000000000000000000100000000000000000000001 000100000100000000000000000000000000000000000000000000000 000000000000000000111100000000000000000001000010000010000 000000000000000000000000000000000000000000000000000000000 000010001000000001111100000100001000001000000000000000000 000000000000000000000000000000000000000000000001000010000 001000001000010000100000100000000000000000000000000000000 000000000000000000000000000000000100000100001000000100001 000001000100000000000000000000000000000000000000000000000 000000000000000000010000010000100000010000100000010100000 000000000000000000000000000000000000000000000000000000000 000001001101000100110001000010000001010000000000000000000 000000000000000000000000000000000000000000000000100110100 010011001000001000000101000000000000000000000000000000000 000000000000000000000000000000000010000010001000000100001 000000010100000000000000000000000000000000000000000000000 000000000000000000000100001000100000010000100000001010000 000000000000000000000000000000000000000000000000000000000 000000001111000011111110000010000000101000000000000000000 000000000000000000000000000000000000000000000000000100001 010000000000010000000100100000000000000000000000000000000 000000000000000000000000000000000000010000101000000000001 000000010100000000000000000000000000000000000000000000000 000000000000000000000001000010100000000001000000001010000 000000000000000000000000000000000000000000000000000000000 000000000010001010000000000100000000101000000000000000000 000000000000000000000000000000000000000000000000000001000 000000000000100000000010100000000000000000000000000000000 000000000000000000000000000000000000000011100000100000010 000000010010000000000000000000000000000000000000000000000 000000000000000000000000001001111111000010000000001001000 000000000000000000000000000000000000000000000000000000000 000000000000010000000000010000000000100100000000000000000 000000000000000000000000000000000000000000000000000000000 100000000010000000000010010000000000000000000000000000000 000000000000000000000000000000000000000000001100001110000 000000010001000000000000000000000000000000000000000000000 000000000000000000000000000000011111001000000000010001000 000000000000000000000000000000000000000000000000000000000 000000000000000001000000100000000010001000000000000000000 000000000000000000000000000000000000000000000000000000000 011000000001000000110001000000000000000000000000000000000 000000000000000000000000000000000000000000010100000000110 001100000100000000000000000000000000000000000000000000000 000000000000000000000000000001010000000111111010000010000 000000000000000000000000000000000000000000000000000000000 000000000001111100110000010010001000010000000000000000000 000000000000000000000000000000000000000000000000000000100 001101001111011000100010000000000000000000000000000000000 000000000000000000000000000000000000000010000010100100110 000001010000000000000000000000000000000000000000000000000 000000000000000000000000001000001010100110000000110000000 000000000000000000000000000000000000000000000000000000000 000000000001000000101010100000000010000000000000000000000 000000000000000000000000000000000000000000000000000000100 000011110100000000001000000000000000000000000000000000000 000000000000000000000000000000000000000010000001000010000 000000100000000000000000000000000000000000000000000000000 000000000000000000000000010000000100010000000000100000000 000000000000000000000000000000000000000000000000000000000 000000000001000000010010000000000010000000000000000000000 000000000000000000000000000000000000000000000000000001000 000001010000000000010000000000000000000000000000000000000 000000000000000000000000000000000000000111000000101000000 000010000000000000000000000000000000000000000000000000000 000000000000000000000000010010000010100000000001000000000 000000000000000000000000000000000000000000000000000000000 000000000001001000001010000000001000000000000000000000000 000000000000000000000000000000000000000000000000000000100 100000101000000000100000000000000000000000000000000000000 000000000000000000000000000000000000000010010000010100000 000100000000000000000000000000000000000000000000000000000 000000000000000000000000001001000001010000000010000000000 000000000000000000000000000000000000000000000000000000000 000000000001000100000101000000001000000000000000000000000 000000000000000000000000000000000000000000000000000000100 010000010100000000100000000000000000000000000000000000000 000000000000000000000000000000000000000010010000001010000 000010000000000000000000000000000000000000000000000000000 000000000000000000000000010001000000101000000001000000000 000000000000000000000000000000000000000000000000000000000 000000000001000100000010100000000010000000000000000000000 000000000000000000000000000000000000000000000000000000100 100000001010000000001000000000000000000000000000000000000 000000000000000000000000000000000000000010010000000101000 000000100000000000000000000000000000000000000000000000000 000000000000000000000000010001000000010100000000010000000 000000000000000000000000000000000000000000000000000000000 000000000001001000000001010000000001000000000000000000000 000000000000000000000000000000000000000000000000000000100 100000000101000000000100000000000000000000000000000000000 000000000000000000000000000000000000000010001000000010100 000000010000000000000000000000000000000000000000000000000 000000000000000000000000001000100000001010000000000100000 000000000000000000000000000000000000000000000000000000000 000000000000100010000000101000000000010000000000000000000 000000000000000000000000000000000000000000000000000000100 100100000010100000000001000000000000000000000000000000000 000000000000000000000000000000000000000101010010000001010 000000000100000000000000000000000000000000000000000000000 000000000000000000000000010101101000000101000000000010000 000000000000000000000000000000000000000000000000000000000 000000000001010101000000010100000000001000000000000000000 000000000000000000000000000000000000000000000000000000101 010000000001010000000000100000000000000000000000000000000 000000000000000000000000000000000000000011110100000000101 000000000001000000000000000000000000000000000000000000000 000000000000000000000000001001010000000010100000000000100 000000000000000000000000000000000000000000000000000000000 000000000000000001000000001010000000000010000000000000000 000000000000000000000000000000000000000000000000000000000 000100000000101000000001111000000000000000000000000000000 000000000000000000000000000000000000000000000011111111111 111111111000000000000000000000000000000000000000000000000 000000000000000000000000000000000001000000010000000100000 000000000000000000000000000000000000000000000000000000000 000000000000000000000100000001000000010000000000000000000 000000000000000000000000000000000000000000000000000000000 000000010000000100000001000000000000000000000000000000000 000000000000000000000000000000000000000000000000001000000 010000000100000000000000000000000000000000000000000000000 000000000000000000000000000000000000100000001000000010000 000000000000000000000000000000000000000000000000000000000 000000000000000000000010000000100000001000000000000000000 000000000000000000000000000000000000000000000000000000000 000000001000000010000000100000000000000000000000000000000 000000000000000000000000000000000000000000000000000111000 001000000010000000000000000000000000000000000000000000000 000000000000000000000000000000000000100011100100111101000 000000000000000000000000000000000000000000000000000000000 000000000000000000000100000001111100001100000000000000000 000000000000000000000000000000000000000000000000000000000 000000100000000001000000001000000000000000000000000000000 000000000000000000000000000000000000000000000000010100000 000100000000100000000000000000000000000000000000000000000 000000000000000000000000000000000001010100000010000000001 000000000000000000000000000000000000000000000000000000000 000000000000000000000101010000001000000000100000000000000 000000000000000000000000000000000000000000000000000000000 000000010101000000100000000010000000000000000000000000000 000000000000000000000000000000000000000000000000001110100 111110000000010000000000000000000000000000000000000000000 000000000000000000000000000000000000000111100001111111110 000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000 0000000000000000000000000111111111100000000001111111111'
# Get rid of the spaces which were included from copying and pasting from the site
data = [c for c in data if c != ' ']
from itertools import izip, chain, repeat
def grouper(n, iterable, padvalue=None):
"grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
return izip(*[chain(iterable, repeat(padvalue, n-1))]*n)
# Put the data into groups of 100 as this is a 100x100 image
data = grouper(100, data)
# I used 101x101 just in case I'd messed up the maths.
img = Image.new('RGB', (101,101))
pixels = img.load()
for y, row in enumerate(data):
for x, v in enumerate(row):
# treat a 0 as white
if v == '0':
pixels[x,y] = (255, 255, 255)
# treat a 1 as black
elif v == '1':
pixels[x, y] = (0, 0, 0)
img.save('alien.jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment