Turtle随机形状

from turtle import *
from random import *
import time

getscreen().colormode(255)
shape(“turtle”)
speed(0)

def randomcolour():
red=randint(0,255)
green=randint(0,255)
blue=randint(0,255)
color(red,green,blue)

def randomplace():
penup()
x=randint(-200,200)
y=randint(-200,200)
goto(x,y)
pendown()

def randomheading():
setheading(randint(1,360))

def drawrectangle():
hideturtle()
lenght=randint(10,100)
height=randint(10,100)
begin_fill()
forward(lenght)
right(90)
forward(height)
right(90)
forward(lenght)
right(90)
forward(height)
right(90)
end_fill()
def drawcircle():
dot(randint(20,100))

def drawfivestar():
circle(randint(5,100),steps=5)

def five():
begin_fill()
x=randint(50,200)
for i in range(5):
forward(x)
right(144)
end_fill()
hideturtle()

for i in range(30):
randomcolour()
randomplace()
stamp()

clear()
setheading(0)
time.sleep(3)

for i in range(20):
randomcolour()
randomplace()
drawrectangle()

clear()
setheading(0)
time.sleep(3)

for i in range(20):
randomcolour()
randomplace()
drawcircle()

clear()
setheading(0)
time.sleep(3)

for i in range(20):
randomcolour()
randomplace()
drawfivestar()

clear()
setheading(0)
time.sleep(3)

for i in range(20):
randomcolour()
randomplace()
five()

turtle.done()