彩虹动画文字

时间:2019-07-16 23:34:31

标签: python-3.x

到目前为止,我正在尝试制作动画彩虹文字(从左到右),直到到达颜色列表(c列表)的最后,一切都在起作用,当我尝试回滚(if x == 18: ; x = 0)时,它确实起作用了

请帮助

import os
import time
from sty import fg, bg, ef, rs, RgbFg

c = [196, 202, 208, 214, 220, 226, 190, 118, 121, 122, 123, 75, 33, 21, 93, 171, 201, 199]

w = "ElapsedTime"

#fg(c[0]) + w[0] + fg(c[0]) + w[1] + fg(c[0]) + w[2] + fg(c[0]) + w[3] + fg(c[0]) + w[4]

final = []
n = 0

def clear():
    time.sleep(.01)
    os.system("clear")

def d001(x):
    y = 0
    while True:
            f101 = fg(c[x]) + w[y]
            final.append(f101)
            x = x+1
            if x == 18:
                x = 0
            if y == 10:
                break
            y = y+1
    print("".join(final))
    final.clear()

while True:
    d001(n)
    print(n)
    n = n+1
    if n == 20:
        break

1 个答案:

答案 0 :(得分:2)

X和Y都将增加1,y == 10x == 18之前变为真并中断循环