[英]How to make spiral spin in turtle?
我正在嘗試制作游戲,並且我制作了主角。
下面是主角的代碼:
from turtle import *
from random import *
chandra = Turtle(shape="turtle")
chandra.speed("fastest")
COLORS = ["orange", "blue", "red", "green", "purple"]
def draw_characterpart1():
for i in range(36):
for i in range(3):
chandra.color(choice(COLORS))
chandra.forward(80)
chandra.right(120)
chandra.left(10)
def draw_characterpart2():
for i in range(36):
for i in range(4):
chandra.color(choice(COLORS))
chandra.forward(70)
chandra.right(90)
chandra.left(10)
def draw_spiral():
for i in range(10, 90, 10):
chandra.color(choice(COLORS))
chandra.circle(i, 180)
draw_characterpart1()
draw_characterpart2()
draw_spiral()
mainloop()
我想讓它旋轉,或者只是旋轉。
我嘗試手動創建角色(沒有 for 循環),然后分配每種顏色。
一旦我這樣做了,我就可以移動 colors。
然而,這是一個非常糟糕的解決方案。
謝謝!
有了烏龜,再加上一點想象力,一切皆有可能……
我唯一的想法是使用復合形狀來創建也許你可以旋轉的烏龜形狀。 – 弗拉斯
用於制作光標的復合形狀需要填充多邊形,在這種情況下很難使用。
但是如果它不起作用,那么您可能需要清除字符並以不同的角度重新繪制它,然后再次清除它並以不同的角度重新繪制,等等。 - furas
是的,這似乎是可行的方法。 但是,使用隨機 colors 在某種程度上可以對抗這種錯覺,所以我改用循環 colors 代替:
from turtle import Screen, Turtle
from itertools import cycle
COLORS = ["orange", "blue", "red", "green", "purple"]
def draw_character():
color = cycle(COLORS)
for _ in range(36):
for _ in range(3):
chandra.color(next(color))
chandra.forward(80)
chandra.right(120)
chandra.left(10)
for _ in range(36):
for _ in range(4):
chandra.color(next(color))
chandra.forward(70)
chandra.right(90)
chandra.left(10)
for radius in range(10, 90, 10):
chandra.color(next(color))
chandra.circle(radius, 180)
screen = Screen()
screen.tracer(False)
chandra = Turtle()
for angle in range(720):
chandra.reset()
chandra.hideturtle()
chandra.left(angle)
draw_character()
screen.update()
screen.tracer(True)
screen.mainloop()
動畫 GIF 只是更好的海龜圖形的采樣近似值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.