punchcard

之前bkp的一道题,有了脚本,就再也不怕看花眼了~

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import Image
import sys

START_PIXEL_X = 17
START_PIXEL_Y = 24

X_NEXT_PIXEL = 7
Y_NEXT_PIXEL = 20

TOTAL_ROWS = 12
TOTAL_COLUMNS = 80

def get_ascii(index1,index2,index3):
if index1 == 1:
if index2 ==4:
return 'a'
elif index2 ==5:
return 'b'
elif index2 ==6:
if index3 == 11:
return '.'
else:
return 'c'
elif index2 == 7:
if index3 == 11:
return '<'
else:
return 'd'
elif index2 == 8:
if index3 ==11:
return '('
else:
return 'e'
elif index2 ==9:
if index3 == 11:
return '+'
else :
return 'f'
elif index2 ==10:
return 'g'
elif index2 == 11:
return 'h'
elif index2 == 12:
return 'i'
elif index2 == 0:
return '&'
elif index1 == 2:
if index2 == 4:
return 'j'
elif index2 == 5:
if index3 == 11:
return '!'
else:
return 'k'
elif index2 == 6:
if index3 == 11:
return '$'
else:
return 'l'
elif index2 == 7:
if index3 == 11:
return '*'
else:
return 'm'
elif index2 == 8:
if index3 ==11:
return ')'
else:
return 'n'
elif index2 == 9:
return 'o'
elif index2 == 10:
return 'p'
elif index2 == 11:
return 'q'
elif index2 == 12:
return 'r'
elif index2 == 0:
return '-'
elif index1 ==3:
if index2 == 5:
return 's'
elif index2 == 4:
return '/'
elif index2 == 6:
if index3 ==11:
return ','
else :
return 't'
elif index2 ==7:
if index3 ==11:
return '%'
else:
return 'u'
elif index2 ==8:
return 'v'
elif index2 ==9:
if index3 ==11:
return '>'
else:
return 'w'
elif index2 == 10:
if index3 ==11:
return '?'
else:
return 'x'
elif index2 == 11:
return 'y'
elif index2 == 12:
return 'z'
elif index1 ==4:
return '1'
elif index1 ==5:
if index2 ==11:
return ':'
else:
return '2'
elif index1 ==6:
if index2 ==11:
return '#'
else:
return '3'
elif index1 ==10:
if index2 == 11:
return '"'
else:
return '7'
elif index1 ==8:
if index2 ==11:
return ''
else:
return '5'
elif index1 == 9:
if index2 == 11:
return '='
else:
return '6'
elif index1 ==7:
if index2 == 11:
return '@'
else:
return '4'
elif index1 == 11:
return '8'
elif index1 == 12:
return '9'
# elif index1 ==0:
# return ''


im = Image.open('123.png')
pix = im.load()
rgb_im = im.convert('RGB')
r,g,b = rgb_im.getpixel((START_PIXEL_X,START_PIXEL_Y))
#stringbuilder = '!'

for x in range(1,TOTAL_COLUMNS+1):
bulletedindex = [0,0,0]
count = 0
for y in range(1,TOTAL_ROWS+1):
r,g,b = rgb_im.getpixel((X_NEXT_PIXEL*x+10,Y_NEXT_PIXEL *y+4))
if r == 20 and g ==20 and b ==20:
bulletedindex[count] = y
count = count +1
# stringbuilder = stringbuilder + get_ascii(bulletedindex[0],bulletedindex[1],bulletedindex[2])
print get_ascii(bulletedindex[0],bulletedindex[1],bulletedindex[2])
#print stringbuilder