创建矩形,它们之间的距离相等,但高度和宽度随机。但是它们之间的距离并不固定并且会改变。
import TurtleHelper
import turtle
import random as rd
def drawRectangle(myTurtle, width, height):
for i in range(2):
myTurtle.fd(width)
myTurtle.left(90)
myTurtle.fd(height)
myTurtle.left(90)
def drawRectangleagain(myTurtle):
myTurtle.up()
myTurtle.forward(100)
myTurtle.down()
def main():
window=TurtleHelper.initWindow()
t=turtle.Turtle()
t.pencolor("blue")
for i in range(3):
drawRectangle(t,rd.randint(20, 60), rd.randint(20, 110))
drawRectangleagain(t)
window.exitonclick()
main()