-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch22.py
More file actions
90 lines (61 loc) · 1.56 KB
/
ch22.py
File metadata and controls
90 lines (61 loc) · 1.56 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from PIL import Image as im
from PIL import ImageDraw
import os
from ch7 import chunks
def extractFrames(inGif, outFolder):
frame = im.open(inGif)
nframes = 0
while frame:
frame.save( '%s/%s.gif' % (outFolder, nframes ) , 'GIF')
nframes += 1
try:
frame.seek( nframes )
except EOFError:
break;
print 'nframes:', nframes
return True
if __name__ == '__main__':
# extractFrames('white.gif', 'ch22_pics')
imgs = []
for root, dirs, filenames in os.walk('./ch22_pics/'):
filenames.remove('.DS_Store')
for f in sorted(filenames, key=lambda n: int(n.split('.')[0])):
imgs.append(im.open('./ch22_pics/' + f))
marks = []
imgctr = 0
for img in imgs:
img = img.convert('RGBA')
li = list(img.getdata())
# print '\nCTR:', imgctr, '\n'
imgctr += 1
# print img.mode
# print img.size
# print len(li)
li = chunks(li,200)
# print len(li[0])
# print len(li)
rc = 1
for row in li:
col = 1
for pix in row:
if pix == (8,8,8,255):
marks.append((rc-1, col-1))
col += 1
rc += 1
print len(marks)
W = 200
H = 200
img = im.new("RGB", (W, H), "black")
draw = ImageDraw.Draw(img)
cur = ()
resetctr = 0
for mark in marks:
if mark == (100, 100):
resetctr += 1
cur = (30*resetctr, 30*resetctr)
continue
dx = mark[0] - 100
dy = mark[1] - 100
draw.line((cur[0], cur[1], cur[0]+dx, cur[1]+dy), "white")
cur = (cur[0] + dx, cur[1]+dy)
img.show()