python - Python 上的 ASCII 动画
问题描述
我希望顶部的烟雾无限移动。我正在寻找一个简单的实现。这是我的代码:
def welcome():
print(" (")
print(" )")
print(" (")
print(" _)")
print(" __________| |____")
print(" / \\")
print(" / Welcome to \\")
print(" / A Horror Game \\")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(1)
解决方案
欢迎新手
下面是一个可能的实现,而不使用任何专门的包。
但是,也要看看这些包:curses和asciimatics。
import time
import platform # Used by clear_screen
import subprocess # Used by clear_screen
# System independent clear screen function
# https://stackoverflow.com/questions/18937058/#42877403
def clear_screen():
command = "cls" if platform.system().lower()=="windows" else "clear"
return subprocess.call(command) == 0
def smoke():
# You could use the random package for a more realistic effect
# https://docs.python.org/3/library/random.html
shift = 15 + smoke.shift
print(" "*(shift+2)+"(")
print(" "*(shift )+")")
print(" "*(shift+2)+"(")
print(" "*(shift )+")")
# Next shift using current direction
smoke.shift += smoke.direction
# Change direction if out of limits
if smoke.shift>3 or smoke.shift<-2:
smoke.direction *= -1
def house():
print(" __________| |____")
print(" / \\")
print(" / Welcome to \\")
print(" / A Horror Game \\")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print()
# MAIN CODE
smoke.shift = 0
smoke.direction = 1 # could be 1 or -1
# print('\033[2J') # One possible method to clear the screen
clear_screen()
# Infinite loop. Use CTR-C to stop
while True:
smoke()
house()
time.sleep(1)
clear_screen()
推荐阅读
- .net - 在 Azure 中发布:不匹配依赖项错误。是什么导致它以及在通过管道使用发布时如何解决它?
- python - TKinter 标签的移动距离不超过我窗口上的某个点
- javascript - Google 幻灯片中的交互式图表演示
- python - Pytorch:具有非常量核的卷积
- python - 功能参数
- python-3.x - NameError:名称“contact_value”未在 serializers.py 中定义
- docker - 使用 Docker Secret 作为 Quarkus 数据源密码
- python-3.x - 循环遍历列表并在函数内返回列表
- javascript - 单击圆环图中的元素
- azure - 为什么 Azure 负载均衡器不适用于不在可用性集中的计算机?