-
Notifications
You must be signed in to change notification settings - Fork 4
/
animate_output.py
executable file
·99 lines (88 loc) · 2.05 KB
/
animate_output.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
#!/usr/bin/env python3
import time
import argparse
import sys
from image2ascii import Image2Ascii as A2I
try:
import pyperclip
except Exception:
pass
parser = argparse.ArgumentParser(
usage='%(prog)s <[-i] [--image]> [Location] || <[-a] [--ascii]> [Location]',
description='''simple python program
that output ascii art with animation.
''')
parser.add_argument(
'-i',
'--image',
nargs='+',
default=False,
help="Location of image")
parser.add_argument(
'-a',
'--ascii',
nargs='+',
default=False,
help="Location of text file containing ascii art")
parser.add_argument(
'-c',
'--clipboard',
action='store_true',
# nargs='+',
help="Copy from clipboard")
parser.add_argument(
'-w',
'--width',
type=int,
default=100,
nargs='?',
help="Width of ascii art")
parser.add_argument(
'-s',
'--speed',
type=float,
default=0.1,
nargs='?',
help="Speed of animation")
args = parser.parse_args()
def help():
parser.print_help()
exit()
def validate():
if(len(sys.argv) <= 1):
help()
def img_to_display():
if args.image:
return 'img'
elif args.ascii:
return 'ascii'
elif args.clipboard:
return 'clip'
class Animate:
def __init__(self, speed=0.01):
self.speed = speed
def animate(self, art):
for _ in art:
print(_, end='', flush=True)
time.sleep(self.speed)
if __name__ == '__main__':
validate()
a = Animate(args.speed)
if img_to_display() == 'img':
asc = A2I(args.image[0] , args.width).convert()
a.animate(asc)
elif img_to_display() == 'ascii':
with open(args.ascii[0], 'r') as f:
a.animate(f.read())
elif img_to_display() == 'clip':
d = None
try:
d = pyperclip.paste()
except Exception:
d = """
Did you just edit the code or you forgot
to install pyperclip module?
"""
a.animate(d)
else:
help()