import time
import math
import os
def cls():
os.system('cls' if os.name=='nt' else 'clear')
FPS=10
PERIOD = 5 # sec
start = time.time()
d = 10
l = 30
f = 2*math.pi/PERIOD
def draw(dt):
cos_dt = math.cos(dt*f)
cls()
for a in range(l):
x = d * a/l * cos_dt
i = round(x) + d
s = ' '*(2*d+1)
s = s[:i] + '*' + s[i+1:]
print(s)
while True:
draw(time.time() - start)
time.sleep(1/FPS)
ASCII 图形可以工作吗?=)
这里是阻尼。Graphics.py 库文档和标准数学