import turtle,random
def randomn():
n= random.randint(1,5)
#阶数
n=int(n)
return n
def randomx():#随机位置x
x= random.randint(-250,250)
x=int(x)
return x
def randomy():#随机位置y
y= random.randint(-200,200)
y=int(y)
return y
def randomsize():
size=random.randint(50, 70)
return size
def randomcolor():#随机颜色
colorArr = ['1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
color = ""
for i in range(6):
color += colorArr[random.randint(0,14)]
return "#"+color
def koch(size,n):
if n==0:
turtle.fd(size)
else:
for angle in [0,45,90,-135,-135,90]:
turtle.color(randomcolor())
turtle.left(angle)
koch(size/6, n-1)
def main():
turtle.setup(1000,700)
turtle.screensize(bg="#F8F8FF")
turtle.pensize(2)
size=randomsize()
n=randomn()
turtle.color(randomcolor())
number= random.choice([3, 4, 5, 6, 7, 8, 9,])
for i in range(0,number):
turtle.penup()
x=randomx()
y=randomy()
turtle.color(randomcolor(),"white")
turtle.goto(x,y)
turtle.speed(2000)
turtle.pendown()
for i in range(6):
koch(size,n)
turtle.right(90)
turtle.hideturtle()
turtle.done()
main()