Python 上的 ASCII 动画
ASCII animation on Python
我想让顶部的烟雾无限移动。我正在寻找一个简单的实现。这是我的代码:
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)
您可能只想做一些简单的事情,例如创建一个 while 循环,该循环使用 print 语句调用多个函数,将烟雾放置在不同的位置,例如:
def welcome2():
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)
或类似的东西。如果你重复调用多个函数,它看起来就像是 smoke "moving." 我不确定你是从哪里调用这个欢迎函数的。
欢迎新手
下面是不使用任何专门包的可能实现。
但是,还要查看这些包:curses and asciimatics.
在此 online interpreter 中查看并使用此示例。
这是一个 animated gif.
import time
import platform # Used by clear_screen
import subprocess # Used by clear_screen
# System independent clear screen function
#
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('3[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()
我认为这是一个有趣的问题,我深有体会。根据 ePi272314 的答案,您可以尝试以下方法以获得另一种很酷的烟雾效果。希望对您有所帮助!
import time
import os
from os import system, name
# define our clear function
def clear():
os.system( 'cls' )
def welcome():
smoke = [' (_)',' ()', ' ()',' ()', ' ()']
print("\n"*4)
print(" _ ")
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*5)
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*4)
print (smoke[1])
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*3)
print (smoke[2])
print (smoke[1])
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*2)
print (smoke[3])
print (smoke[2])
print (smoke[1])
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*1)
print (smoke[4])
print (smoke[3])
print (smoke[2])
print (smoke[1])
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
while True:
welcome()
print('3[2J')
我想让顶部的烟雾无限移动。我正在寻找一个简单的实现。这是我的代码:
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)
您可能只想做一些简单的事情,例如创建一个 while 循环,该循环使用 print 语句调用多个函数,将烟雾放置在不同的位置,例如:
def welcome2():
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)
或类似的东西。如果你重复调用多个函数,它看起来就像是 smoke "moving." 我不确定你是从哪里调用这个欢迎函数的。
欢迎新手
下面是不使用任何专门包的可能实现。
但是,还要查看这些包:curses and asciimatics.
在此 online interpreter 中查看并使用此示例。
这是一个 animated gif.
import time
import platform # Used by clear_screen
import subprocess # Used by clear_screen
# System independent clear screen function
#
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('3[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()
我认为这是一个有趣的问题,我深有体会。根据 ePi272314 的答案,您可以尝试以下方法以获得另一种很酷的烟雾效果。希望对您有所帮助!
import time
import os
from os import system, name
# define our clear function
def clear():
os.system( 'cls' )
def welcome():
smoke = [' (_)',' ()', ' ()',' ()', ' ()']
print("\n"*4)
print(" _ ")
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*5)
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*4)
print (smoke[1])
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*3)
print (smoke[2])
print (smoke[1])
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*2)
print (smoke[3])
print (smoke[2])
print (smoke[1])
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
print("\n"*1)
print (smoke[4])
print (smoke[3])
print (smoke[2])
print (smoke[1])
print (smoke[0])
print(" __________| |____")
print(" / \")
print(" / Welcome to \")
print(" / A Horror Game \")
print(" | By: A.D & T.P |")
print(" | ____ ___ |")
print(" | | | |___| |")
print("__|____|____|___________|__")
print("")
time.sleep(.6)
clear()
while True:
welcome()
print('3[2J')