Commit | Line | Data |
---|---|---|
2a6238f5 O |
1 | import random |
2 | import itertools | |
8c840a83 O |
3 | from functools import wraps |
4 | from termcolor import * | |
5 | from pyfiglet import figlet_format | |
6 | ||
2a6238f5 O |
7 | grey = lambda x: colored(x, 'grey', attrs=['bold']) |
8 | red = lambda x: colored(x, 'red', attrs=['bold']) | |
9 | green = lambda x: colored(x, 'green', attrs=['bold']) | |
10 | yellow = lambda x: colored(x, 'yellow', attrs=['bold']) | |
11 | blue = lambda x: colored(x, 'blue', attrs=['bold']) | |
8c840a83 | 12 | magenta = lambda x: colored(x, 'magenta', attrs=['bold']) |
2a6238f5 O |
13 | cyan = lambda x: colored(x, 'cyan', attrs=['bold']) |
14 | white = lambda x: colored(x, 'white', attrs=['bold']) | |
8c840a83 | 15 | |
2a6238f5 O |
16 | on_grey = lambda x: colored(x, 'white', 'on_grey', attrs=['bold']) |
17 | on_red = lambda x: colored(x, 'white', 'on_red', attrs=['bold']) | |
18 | on_green = lambda x: colored(x, 'white', 'on_green', attrs=['bold']) | |
19 | on_yellow = lambda x: colored(x, 'white', 'on_yellow', attrs=['bold']) | |
20 | on_blue = lambda x: colored(x, 'white', 'on_blue', attrs=['bold']) | |
8c840a83 | 21 | on_magenta = lambda x: colored(x, 'white', 'on_magenta', attrs=['bold']) |
2a6238f5 O |
22 | on_cyan = lambda x: colored(x, 'white', 'on_cyan', attrs=['bold']) |
23 | on_white = lambda x: colored(x, 'white', 'on_white', attrs=['bold']) | |
8c840a83 | 24 | |
668db21c | 25 | colors_shuffle = [grey, red, green, yellow, blue, magenta, cyan] |
2a6238f5 O |
26 | background_shuffle = [ |
27 | on_grey, | |
28 | on_red, | |
29 | on_green, | |
30 | on_yellow, | |
31 | on_blue, | |
32 | on_magenta, | |
33 | on_cyan] | |
668db21c | 34 | cyc = itertools.cycle(colors_shuffle[1:]) |
8c840a83 O |
35 | |
36 | ||
37 | def order_rainbow(s): | |
38 | """ | |
39 | Print a string with ordered color with each character | |
40 | """ | |
2a6238f5 O |
41 | c = [colors_shuffle[i % 7](s[i]) for i in xrange(len(s))] |
42 | return reduce(lambda x, y: x + y, c) | |
43 | ||
8c840a83 O |
44 | |
45 | def random_rainbow(s): | |
46 | """ | |
47 | Print a string with random color with each character | |
48 | """ | |
668db21c | 49 | c = [random.choice(colors_shuffle)(i) for i in s] |
2a6238f5 O |
50 | return reduce(lambda x, y: x + y, c) |
51 | ||
8c840a83 O |
52 | |
53 | def Memoize(func): | |
54 | """ | |
55 | Memoize decorator | |
56 | """ | |
57 | cache = {} | |
2a6238f5 | 58 | |
8c840a83 O |
59 | @wraps(func) |
60 | def wrapper(*args): | |
61 | if args not in cache: | |
62 | cache[args] = func(*args) | |
63 | return cache[args] | |
64 | return wrapper | |
65 | ||
2a6238f5 | 66 | |
8c840a83 O |
67 | @Memoize |
68 | def cycle_color(s): | |
69 | """ | |
668db21c | 70 | Cycle the colors_shuffle |
8c840a83 O |
71 | """ |
72 | return next(cyc)(s) | |
73 | ||
2a6238f5 | 74 | |
42fde775 | 75 | def ascii_art(text): |
8c840a83 O |
76 | """ |
77 | Draw the Ascii Art | |
78 | """ | |
42fde775 | 79 | fi = figlet_format(text, font='doom') |
8c840a83 | 80 | print('\n'.join( |
2a6238f5 O |
81 | [next(cyc)(i) for i in fi.split('\n')] |
82 | ) | |
8c840a83 | 83 | ) |