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