2 回答

TA贡献1963条经验 获得超6个赞
我认为对于您的代码,您将需要使用该setpos()
方法。
此方法将turtle 中的屏幕视为具有四个象限的坐标平面。
使用它,相应地设置 x 和 y 坐标,或者根据需要随机设置。
例如,每次运行时都会将海龟放在随机位置:
from turtle import *
t = Turtle()
t.penup()
from random import randint
x = randint(-200, 200)
y = randint(-200, 200)
t.setpos(x, y)
希望这可以帮助!!!

TA贡献1829条经验 获得超7个赞
根据您对问题的描述,您似乎想要以下内容:
from turtle import Screen, Turtle
from random import sample, random
RADIUS = 100
PETALS = 10
def draw_petal(t, radius):
heading = t.heading()
t.circle(radius, 60)
t.left(120)
t.circle(radius, 60)
t.setheading(heading)
def draw_flower(t):
for _ in range(PETALS):
draw_petal(t, RADIUS)
t.left(360 / PETALS)
def draw_flowers(t, stemX):
stemYcoordinates = sorted(sample(range(-200, 0), 9))
for stemYcoordinate in stemYcoordinates:
t.setheading(90)
t.pensize(7 + stemYcoordinate // 40)
t.color(random(), random(), random())
t.penup()
t.goto(stemX, stemYcoordinate)
t.pendown()
draw_flower(t)
screen = Screen()
turtle = Turtle(visible=False)
turtle.speed('fastest') # because I have no patience
draw_flowers(turtle, 0)
screen.exitonclick()
但是,如果这不是您要找的内容,请花时间重新阅读和编辑您的问题以阐明您想要做什么。添加更多(如果不是全部)您迄今为止编写的代码,以明确您需要帮助的内容。
添加回答
举报