gpt4 book ai didi

python - Python 上的 ASCII 动画

转载 作者:行者123 更新时间:2023-12-04 01:31:55 25 4
gpt4 key购买 nike

我想让顶部的烟雾无限移动。我正在寻找一个简单的实现。这是我的代码:

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)

最佳答案

欢迎新手

下面是不使用任何专用包的可能实现。
但是,还要查看这些包:cursesasciimatics .

在这个 online interpreter 中查看并使用这个示例.
这是一个 animated gif .

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()

关于python - Python 上的 ASCII 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60783120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com