あなたは定期的に新しい色で四角形を再描画する関数を実行するためにontimer()
を使用することができます。
私は
ontimer()
の使用に関する@furas(+1)と一致していますがrectanglar形状で作業している場合、私はあなたの四角形を表すためにカメを使用して、シンプルな実装で行くと亀さんを変えたい
import turtle as t
def rect(c):
t.color(c)
t.begin_fill()
for _ in range(4):
t.forward(100)
t.right(90)
t.end_fill()
def fade():
global c
# draw
rect(c)
# change color
r, g, b = c
r += 0.1
g += 0.1
b += 0.1
c = (r, g, b)
# repeat function later
if r <= 1.0 and g <= 1.0 and b <= 1.0:
# run after 100ms
t.ontimer(fade, 100)
# --- main ---
# run fast
t.speed(0)
# starting color
c = (0,0,0) # mode 1.0 color from (0.0,0.0,0.0) to (1.0,1.0,1.0)
# start fadeing
fade()
# start "the engine" so `ontimer` will work
t.mainloop()
「ontimer」を使用して、それを新しい色で再描画する定期的機能を実行することができます。 – furas