Python中制作有趣的流水灯

1. 普通的流水灯

import time
import sys
FRESH_TIME = 0.3
LENGTH = 7
mod = 1
if mod == 1:
    print("Flowing light:")
    while mod == 1:
        for i in range(LENGTH):
            bar = ['['] + [' '] * LENGTH + [']']
            bar[i + 1] = '*'
            bar_show = ''.join(bar)
            print('\r{}'.format(bar_show), end='')
            time.sleep(FRESH_TIME)

2. 积累效果的流水灯

elif mod == 2:
    print("Accumulated flowing light:")
    while mod == 2:
        for j in range(LENGTH):
            for i in range(LENGTH - j):
                bar = ['['] + [' '] * (LENGTH - j) + ['*'] * j + [']']
                bar[i + 1] = '*'
                bar_show = ''.join(bar)
                print('\r{}'.format(bar_show), end='')
                time.sleep(FRESH_TIME)
        time.sleep(FRESH_TIME)

3. 来回效果的流水灯

elif mod == 3:
    print("Round flowing light:")
    while mod == 3:
        for j in range(2):
            for i in range(LENGTH):
                bar = ['['] + [' '] * LENGTH + [']']
                if j == 0:
                    bar[i + 1] = '*'
                else:
                    bar[-(i + 2)] = '*'
                bar_show = ''.join(bar)
                print('\r{}'.format(bar_show), end='')
                time.sleep(FRESH_TIME)

4. 文字流水灯

elif mod == 4:
    print("Flowing word light:")
    word = "I LOVE U"
    while mod == 4:
        bar = ['['] + ['*'] * len(word) + [']']
        bar_show = ''.join(bar)
        print('\r{}'.format(bar_show), end='')
        time.sleep(FRESH_TIME)
        for i in range(len(word)):
            bar[i + 1] = word[i]
            bar_show = ''.join(bar)
            print('\r{}'.format(bar_show), end='')
            time.sleep(FRESH_TIME)

5. 进度条(更完善的进度条请点击Python中制作带数字的进度条

elif mod == 5:
    print("Process bar:")
    while mod == 5:
        for i in range(LENGTH):
            bar = ['['] + [' '] * LENGTH + [']']
            for j in range(i + 1):
                bar[j + 1] = '*'
            bar_show = ''.join(bar)
            print('\r{}'.format(bar_show), end='')
            time.sleep(FRESH_TIME)

还有一些有趣的想法,以后更新..

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值