# 实验八

 1 from turtle import *
2
3 def square(size=50, rgb='orange'):
4     '''绘制正方形
5     参数size指定边长
6     参数rgb指定画笔颜色
7     如果没有给参数，采用默认值
8     '''
9     pencolor(rgb)
10     for i in range(4):
11         fd(size)
12         left(90)
13
14
15 def main():
16     setup(800, 600)
17     speed(0)
18
19     n = 10
20     for i in range(n):
21         square(80)
22         left(360/n)
23
24     hideturtle()
25     done()
26
27
28 if __name__ == '__main__':
29     main()
 1 from turtle import *
2 setup(800,600)
3 speed(0)
4 pencolor('pink')
5 n=10
6 for i in range(n):
7     for j in range(2):
8         circle(80,90)
9         left(90)
10     right(360/n)
11
12 hideturtle()
13 done()

 1 from turtle import *
2 setup(800,600)
3 speed(0)
4 pencolor('white')
5 bgcolor('black')
6
7 angle=0
8 size=2
9
10 n=10
11 for i in range(n):
12     for j in range(4):
13         fd(size)
14         angle+=71
15         seth(angle)
16         size+=5
17
18
19 hideturtle()
20 done()

 1 from turtle import *
2 from random import random
3 setup(800,600)
4 speed(0)
5 def rect(w,h,fc):
6     fillcolor(fc)
7     for i in range(1,5):
8         if i%2==1:
9             d=w
10         else:
11             d=h
12         fd(d)
13         left(90)
14 def moveto(x,y):
15     penup()
16     goto(x,y)
17     pendown()
18 for i in range(10):
19     moveto(-20*i,0)
20     rgb=tuple(random()for i in range(3))
21     begin_fill()
22     rect(20,50,rgb)
23     end_fill()
24 for i in range(10):
25     moveto(20*i,0)
26     rgb=tuple(random()for i in range(3))
27     begin_fill()
28     rect(20,50,rgb)
29     end_fill()
30 hideturtle()
31 done()

posted @ 2022-06-14 10:43  pray4hell  阅读(7)  评论(1编辑  收藏  举报