-
Notifications
You must be signed in to change notification settings - Fork 9
/
extract.py
68 lines (58 loc) · 1.49 KB
/
extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python2
from glob import glob
from PIL import Image
import sys
images = sorted(glob("frame_*.gif"))
charwidth=8
charheight=13
charset=[]
charmap=[' ', '@', '~', 't', '(', '%', '^', 's',
'/', 'C', 'G', 'O', '#', '7']
def printchar(c, char):
if c < len(charmap):
sys.stdout.write(charmap[c])
else:
print_unknown(char)
sys.exit(1)
def print_unknown(char):
matrix = [[0 for x in xrange(20)] for x in xrange(20)]
i = 0
for c in char:
x = i / 11
y = i % 11
matrix[y][x] = c
i += 1
print
print "unknown:"
print "'''"
for y in range(len(matrix)):
for x in range(len(matrix[y])):
c = matrix[y][x]
if c == 1:
pixel = ' '
elif c == 0:
pixel = '#'
else:
raise
sys.stdout.write(pixel)
print
print "'''"
print "import time"
for imagename in images:
print "time.sleep(0.2)"
print "print \"\033[2J\033[;H\" "
print "print \"\"\""
image = Image.open(imagename)
for row in range(0, image.size[1], charheight):
for col in range(0, image.size[0]-charwidth, charwidth):
# This gives us the index of each character.
# we pull that into a list and output either the char or index
char=[]
for charcol in range(col, col+charwidth):
for charrow in range(row, row+charheight-2):
char.append(image.getpixel((charcol, charrow)))
if not char in charset:
charset.append(char)
printchar(charset.index(char), char)
print
print "\"\"\""