spacepaste

 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
import time
import sys
from string import lowercase
from random import choice

colors = ("grey", "red", "green", "yellow", "blue", "magenta", "cyan")
attributes = ("bold", "underline", "blink", "reverse")

def rand_col(): return choice(colors)
def rand_on_col(): return "on_" + rand_col()
def rand_attr(): return choice(attributes)

def style(ch, c1=None, c2=None, atr=None):
    if atr: return termcolor.colored(ch, c1(), c2(), attrs=[atr()])
    elif c2: return termcolor.colored(ch, c1(), c2())
    elif c1: return termcolor.colored(ch, c1())
    else: return ch

states = { 0: (rand_col, rand_on_col, rand_attr),
           1: (rand_col, rand_col),
           2: (rand_col, ), }

for _ in range(100):
    print style(choice(lowercase), *choice(states))
    sys.stdout.flush()
    time.sleep(0.3)