-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.py
100 lines (73 loc) · 3.59 KB
/
utils.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
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
import os
from random import randint
import hashlib
DIR_PATH = os.path.dirname(os.path.realpath(__file__))
#pretty log
def plog(text):
n = len(text) + 4
print "%s \n %s \n%s"%('*'*n,text,'*'*n)
def find_all(string, sub):
return [i for i in range(len(string)) if string.startswith(sub, i)]
def typing_animation(string,speed='9',output=''):
string = string + " "
string = string.replace("'",'"')
unique_id = hashlib.md5(string).hexdigest()[:6]
os.system("mkdir %s/%s"%(DIR_PATH,unique_id))
arr= []
for counter,char in enumerate(string):
word = string[:counter]
print word,counter
arr.append([counter,word])
os.system("convert -background white -gravity northwest -fill black -pointsize 17 -size 500x500 caption:'%s' %s/%s/%s.png"%(word,DIR_PATH,unique_id,counter))
if (counter + 1) == len(string):
for i in xrange(1,5):
counter = counter + 1
word = string
arr.append([counter,word])
os.system("convert -background white -gravity northwest -fill black -pointsize 17 -size 500x500 caption:'%s' %s/%s/%s.png"%(word,DIR_PATH,unique_id,counter))
os.system("ffmpeg -i %s/%s/%%1d.png %s/%s/semi_final.gif"%(DIR_PATH,unique_id,DIR_PATH,unique_id))
os.system("convert -delay 10x%s0 %s/%s/semi_final.gif %s/%s/final.gif"%(speed,DIR_PATH,unique_id,DIR_PATH,unique_id))
if not output:
output="%s/%s.gif"%(DIR_PATH,unique_id)
else:
pass
os.system("cp %s/%s/final.gif %s/%s"%(DIR_PATH,unique_id,DIR_PATH,output))
os.system("rm -rf %s/%s"%(DIR_PATH,unique_id))
os.system("open -a 'Google Chrome' %s"%(output))
plog(unique_id)
def blinking_animation(string,speed='3',output=''):
string.encode('ascii',errors='ignore')
string = string.replace("'",'"')
unique_id = hashlib.md5(string).hexdigest()[:6]
for i in range(10):
string = string.split(" ")[0] + " " + string
for i in range(15):
string = string + " " + string.split(" ")[-1]
word_arr = string.split(" ")
os.system("mkdir %s/%s"%(DIR_PATH,unique_id))
for counter,word in enumerate(word_arr):
print word,counter
#gen_image(unique_id,word,counter)
os.system("convert -background white -gravity center -fill black -pointsize 17 -size 100x100 caption:'%s' %s/%s/%s.png"%(word,DIR_PATH,unique_id,counter))
#os.system("convert %s/yellow.png -gravity center -weight Bold -pointsize 20 -annotate 0 '%s' %s/%s/%s.png"%(DIR_PATH,word,DIR_PATH,unique_id,counter))
os.system("ffmpeg -i %s/%s/%%1d.png %s/%s/semi_final.gif"%(DIR_PATH,unique_id,DIR_PATH,unique_id))
os.system("convert -delay 10x%s0 %s/%s/semi_final.gif %s/%s/final.gif"%(speed,DIR_PATH,unique_id,DIR_PATH,unique_id))
if not output:
output="%s/%s.gif"%(DIR_PATH,unique_id)
else:
pass
os.system("cp %s/%s/final.gif %s/%s"%(DIR_PATH,unique_id,DIR_PATH,output))
os.system("rm -rf %s/%s"%(DIR_PATH,unique_id))
os.system("open -a 'Google Chrome' %s"%(output))
'''
FontExperiment
convert -size 32x32 xc:white empty.jpg
convert yellow.png -gravity center -pointsize 72 -annotate 0 'FoodchamberIsle' lol.png
convert yellow.png -gravity center -weight Bold -annotate 0 'FoodChamberIsle' lol.png
convert mail_canvas.png -gravity northwest -pointsize 17 -size 500x caption:'food chamber' test.png
'''
if __name__ == '__main__':
string = '''Not unnaturally, many elevators imbued with intelligence and precognition became terribly frustrated with the mindless business of going up and down, up and down, experimented briefly with the notion of going sideways, as a sort of existential protest, demanded participation in the decision-making process and finally took to squatting in basements sulking
'''
blinking_animation(string,speed='3')
typing_animation(string,speed='9')