# Python的艺术玩法——“孔雀开屏”篇

```from turtle import *
from random import *
from math import *
myColor=['green', 'yellow','red','purple', 'blue','green', 'orange', 'blue']  #孔雀每环颜色
myR=[180,130,90,60,40,30,20,10]  # 孔雀每环半径
myRb=[60, 50,40,30,25,20,15,10]

def init():  #初始化
screensize(500,500)
speed(0)
penup()
def drawcircle(c,r): # 画圆圈
fillcolor(c)
begin_fill()
circle(r)
end_fill()
def peacock(): # 画孔雀
pendown()
for i in range(8):
drawcircle(myColor[i],myR[i])
penup()
def controlR(x):#调整半径比例
for i in range(len(myR)):
myR[i]=myR[i]*x
def run(n,bigR):  #最终运行函数,bigR为组合的大图形半径
#注意：right()left()函数按角度计算，三角函数按照弧度计算
angle=2*pi/n
right(90+360/n)
for i in range(n):
x=cos(angle*i)*bigR
y=sin(angle*i)*bigR
goto(x,y)
left(360/n)
peacock()

def run2(n,bigR):  #与run()区别：这里是半圆
angle=pi/n
right(90+180/n)
for i in range(n):
x=cos(angle*i)*bigR
y=sin(angle*i)*bigR
goto(x,y)
left(180/n)
peacock()
def run2(n,bigR,scale):  #最终运行函数,bigR为组合的大图形半径,scale代表弧度与2pi的比例
#注意：right()left()函数按角度计算，三角函数按照弧度计算
angle=2*pi/n*scale
right(90+360/n*scale)
for i in range(n):
x=cos(angle*i)*bigR
y=sin(angle*i)*bigR
goto(x,y)
left(360/n*scale)
peacock()

'''
#执行效果1
init()
goto(0,-160)
peacock()
controlR(0.4)
run(10,200)

#执行效果2
init()
write('PEACOCK',True, align="center",font=('Arial',30,'normal'))
controlR(0.5)
run(8,160)

#执行效果3
init()
controlR(0.1)
run(10,50)
init()
controlR(4)
left(150)
run(10,150)
goto(0,-350)
write('PEACOCK',True, align="center",font=('Arial',30,'normal'))
'''
#执行效果4
init()
goto(0,-200)
peacock()
controlR(0.4)
run2(10,200,0.55)
goto(0,-320)
write('PEACOCK',True, align="center",font=('Arial',30,'normal'))```

### 效果一

```#执行效果1
init()
goto(0,-160)
peacock()
controlR(0.4)
run(10,200)```

### 效果二

```#执行效果2
init()
write('PEACOCK',True, align="center",font=('Arial',30,'normal'))
controlR(0.5)
run(8,160)```

### 效果三

```#执行效果3
init()
controlR(0.1)
run(10,50)
init()
controlR(4)
left(150)
run(10,150)
goto(0,-350)
write('PEACOCK',True, align="center",font=('Arial',30,'normal'))```

### 效果四

```#执行效果4
init()
goto(0,-200)
peacock()
controlR(0.4)
run2(10,200,0.55)
goto(0,-320)
write('PEACOCK',True, align="center",font=('Arial',30,'normal'))```

51 篇文章18 人订阅

0 条评论

3675

2200

1062

3619

3257

2179

1985

4175

24410

1082