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