我要画三个一模一样的东西,但是位置,大小都不一样,有什么方式可以让我不要一个一个的画啊
设计一个函数,接收参数为位置、大小、方向
import random
import turtle
def draw(t, pos, length,edgeCount=4, color='red'):
t.up()
t.setpos(pos[0], pos[1])
t.seth(0)
t.pencolor(color)
t.pd()
for i in range(edgeCount):
t.fd(length)
t.lt(360 / edgeCount)
t.up
return t.xcor(), t.ycor()
T = turtle.Turtle()
pos = (-50, -50)
length = 100
for i in range(5):
length = random.randint(30, 90)
xx, yy = draw(T, pos, length, 8)
pos = (xx+ random.randint(-length, 100), yy + random.randint(-length, 100))
turtle.done()