使用python语言,利用turtle库绘画出了一个随机花蕾图,程序中使用了随机函数,所以每次运行结束展示的效果图都会不一样,图片展示:

python源代码展示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

import turtle
import random
turtle.tracer(100)


def drawLine(drawColor,a,b,ra,rb):
turtle.left(90)
turtle.color(drawColor)
turtle.pensize(1.8)
turtle.circle(ra,a/2)
turtle.pensize(1.6)
turtle.circle(ra,a/2)
turtle.pensize(1.4)
turtle.circle(-rb,b/2)
turtle.pensize(1.2)
turtle.circle(-rb,b/2)
turtle.penup()
turtle.right(180)
turtle.circle(rb,b)
turtle.circle(-ra,a)
turtle.left(180)
turtle.pendown()
turtle.right(90)

def flower1(mySize,myLen,myColor): #花 六个花瓣 参数:画笔size 花瓣len 颜色color
turtle.pensize(mySize)
turtle.color(myColor)
turtle.pendown()
time=0
while time<6:
turtle.fd(myLen)
turtle.left(120)
turtle.fd(myLen)
turtle.right(60)
time+=1
turtle.penup()

def rflower(left,s,rlena,rlenb,k,stepa,stepb): #画花的范围left 间隔s 花瓣大小 rCur 花间间隔stepa stepb
while k>left:
turtle.right(90)
turtle.fd(-k)
k-=s
turtle.fd(k)
turtle.left(90)
twoCircle=0
while twoCircle<360:
c=random.randint(0,1)
if c:
flower1(random.randint(2,5),random.randint(rlena,rlenb),"#FF1493")
else:
flower1(random.randint(2,5),random.randint(rlena,rlenb),"#FFB6C1")
turtle.penup()
step=random.randint(stepa,stepb)
turtle.circle(k,step)
twoCircle+=step
return left-5



#turtle.setup(600,600)
turtle.getscreen().bgcolor("black")
#turtle.speed(2000)

turtle.penup()
turtle.fd(250)
turtle.left(90)
'''
#delect start..........
turtle.pendown()
turtle.color("#FFFFFF")
turtle.circle(250,360)
turtle.penup()
#delete end............
'''
turtle.pendown()

# 深粉色 #FF1493
# 浅粉红 #FFB6C1
### 步骤1 ###

oneCircle=0
while oneCircle<720:
ra=random.randint(100,150) #曲线半径
a=random.randint(10,30) #曲线第一段的弧度
rb=random.randint(50,200) #曲线半径
b=random.randint(10,30) #曲线第二段的弧度
if oneCircle<360:
drawLine("#FF1493",a,b,ra,rb)
else:
drawLine("#FFB6C1",a,b,ra,rb)
step=random.randint(3,7)
turtle.penup()
turtle.circle(250,step)
turtle.pendown()
oneCircle+=step

### 步骤2 ###
turtle.penup()
k=245
k=rflower(220,random.randint(10,20),1,3,k,3,20)
k=rflower(150,random.randint(30,50),2,6,k,20,50)
k=rflower(85,random.randint(50,70),5,15,k,50,100)


turtle.update()