-
Notifications
You must be signed in to change notification settings - Fork 0
/
animate_alien.py
82 lines (69 loc) · 2.98 KB
/
animate_alien.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
from moviepy.editor import *
import sys
MORSE_CODE_DICT = { 'A':'.-', 'B':'-...',
'C':'-.-.', 'D':'-..', 'E':'.',
'F':'..-.', 'G':'--.', 'H':'....',
'I':'..', 'J':'.---', 'K':'-.-',
'L':'.-..', 'M':'--', 'N':'-.',
'O':'---', 'P':'.--.', 'Q':'--.-',
'R':'.-.', 'S':'...', 'T':'-',
'U':'..-', 'V':'...-', 'W':'.--',
'X':'-..-', 'Y':'-.--', 'Z':'--..',
'1':'.----', '2':'..---', '3':'...--',
'4':'....-', '5':'.....', '6':'-....',
'7':'--...', '8':'---..', '9':'----.',
'0':'-----', ', ':'--..--', '.':'.-.-.-',
'?':'..--..', '/':'-..-.', '-':'-....-',
'(':'-.--.', ')':'-.--.-'}
def encrypt(message):
cipher = ''
for letter in message:
if letter != ' ':
# Looks up the dictionary and adds the
# corresponding morse code
# along with a space to separate
# morse codes for different characters
cipher += MORSE_CODE_DICT[letter]
else:
# 1 space indicates different characters
# and 2 indicates different words
cipher += ' '
return cipher
def animate_alien(text):
morse = encrypt(text.upper())
clip = [
"default to thumb out",
"default to fingers out",
"fingers out to default",
"fingers out to thumb out",
"thumb out to default",
"thumb out to fingers out",
"fingers out to fingers out",
"thumb out to thumb out"
]
morse = morse.strip()
result = []
result.append("default to fingers out" if morse[0] == "." else "default to thumb out")
for i in range(1, len(morse) - 1):
if morse[i - 1] == "-" and morse[i] == "-":
result.append("thumb out to thumb out")
elif morse[i - 1] == "-" and morse[i] == ".":
result.append("thumb out to fingers out")
elif morse[i - 1] == "-" and morse[i] == " ":
result.append("thumb out to default")
elif morse[i - 1] == "." and morse[i] == "-":
result.append("fingers out to thumb out")
elif morse[i - 1] == "." and morse[i] == ".":
result.append("fingers out to fingers out")
elif morse[i - 1] == "." and morse[i] == " ":
result.append("fingers out to default")
elif morse[i - 1] == " " and morse[i] == "-":
result.append("default to thumb out")
elif morse[i - 1] == " " and morse[i] == ".":
result.append("default to fingers out")
final_videos = []
for clip in result:
final_videos.append(VideoFileClip("alien animation/" + clip + ".mp4"))
final_video = concatenate_videoclips(final_videos, method="compose")
final_video.write_videofile("alien_morse.mp4", verbose=False, logger=None, threads=64, fps=20)
animate_alien(sys.argv[1])