# coding:utf-8#JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 importturtleimportrandomimporttimedefmove():t.forward(30)def画正方形(i):x,y=t.position()x+=iy+=inew_x=xnew_y=yx+=30t.setx(x)y+=30t.sety(y)x-=30t.setx(x)y-=40t.sety(y)new_x=0new_y=0i=0wn=turtle.Screen()wn.setup=(random.randint(600,800),random.randint(700,900))t=turtle.Turtle()t.color('black')t.width(1)t.speed(10)t.goto(0,0)t.hideturtle()turtle.listen()turtle.onkey(move,'k')fori in range(100):ifnew_x<=-600:i=-100画正方形(i)time.sleep(0.5)t.clear()turtle.mainloop()