1
我想在烏龜屏幕上輸出一個變量。但隨着變量的變化,先前的值仍然在屏幕上。因此,這些值是重疊的。方法turtle.clear()
不能解決問題,因爲它會導致屏幕上的值閃爍。如何在烏龜屏幕上輸出變量?
# -*- coding: utf-8 -*-
import turtle
from math import *
s = turtle.Screen()
body = turtle.Turtle()
time_t = turtle.Turtle()
time_t.penup() # For time output
time_t.ht()
def Motion(A=100, omega=5, N=2):
n = 0
t = 0
def x_pos(t):
return A*cos(0.5*omega*t) # x
def y_pos(t):
return A*sin(1*omega*t) # Кy
body.setposition(x_pos(t),y_pos(t))
body.pendown()
while n<N:
body.setposition(x_pos(t),y_pos(t))
t = round(t + 0.01,2)
time_t.setposition(200,200) # In this position I want to output variable
time_t.write("t = " + str(t)) # Show the time variable t on screen
if int(round(t/(2*pi/omega),2)) == n + 1:
n = n + 1
body.penup()
body.color('red')
body.shape('circle')
Motion()
turtle.done()
如果它不應該閃爍,你在期待什麼?你的要求是什麼?你想輸出你的最終't'值是2.51嗎? –