如何在乌龟中进行螺旋旋转?

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 循环)然后分配每种颜色。

一旦我这样做了,我就可以改变颜色了。

然而,这是一个非常糟糕的解决方案。

谢谢!

有了乌龟,再加上一点想象力,一切皆有可能...

my only idea is to use compound-shapes to create turtle shape which maybe you could rotate. – furas

用于制作光标的复合形状需要填充多边形,这在这种情况下很难处理。

But if it will not work then you may need to clear character and draw it again with different angle, and later clear it again and draw again with different angle, etc. – furas

是的,这似乎是可行的方法。然而,使用随机颜色会在某种程度上抵消这种错觉,所以我改用循环颜色:

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 只是更好的海龟图形的近似采样。