-
Notifications
You must be signed in to change notification settings - Fork 1
/
bad_apple.py
36 lines (32 loc) · 1015 Bytes
/
bad_apple.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
import glob,os,time
from PIL import Image
class Text(object):
def __init__(self,inputdir):
self.inputdir=inputdir
self.piclist=glob.glob(self.inputdir+os.path.sep+'*.bmp')
self.piclist=sorted(self.piclist,key=os.path.getmtime)
def pictotext(self,picpath):
pic=Image.open(picpath)
pic=pic.resize((80,30))
pic=pic.convert('L')
width,height=pic.size
text=''
pix=pic.load()
for row in xrange(height):
for col in xrange(width):
if (int(pix[col,row])<128) :
text+='#'
else:
text+=' '
text+='\n'
return text
def main():
display=Text('image')
choice=raw_input('play it or not y/n?\n')
if choice is 'y':
for i in display.piclist:
time.sleep(0.028)
os.system('clear')
char=display.pictotext(i)
print char
main()