teacher_code_python/美丽的雪花.py

49 lines
1020 B
Python
Raw Permalink Normal View History

import turtle
import random
# listx=[0]
# listy=[0]
#
# listcx = []
# listcy = []
#
# for p in range(25):
# listcx.append(0)
# listcy.append(0)
# listx.append(0)
# listy.append(0)
t=turtle.Turtle()
t.speed(0)
for i in range(40):
step = random.randint(20, 50)
r=random.random()
g=random.random()
b=random.random()
x = random.randint(-400, 400)
y = random.randint(-300, 300)
# is_xing=0
# while is_xing==0:
# is_xing=1
# x = random.randint(-400, 400)
# y = random.randint(-300, 300)
# for j in range(i-1):
# listcx[j] = abs(x - listx[j])
# listcy[j] = abs(y - listy[j])
# for k in range(i+1):
# if listcy[k] <= 200 or listcy[k] <= 200:
# is_xing = 0
# listx[i]=x
# listy[i]=y
t.penup()
t.goto(x,y)
t.pendown()
t.pencolor(r, g, b)
for a in range(6):
t.forward(step)
t.penup()
t.goto(x,y)
t.pendown()
t.right(60)