实验八

 1 from turtle import*
 2 def square(size=50,rgb='orange'):
 3     pencolor(rgb)
 4     for i in range(4):
 5         fd(size)
 6         left(90)
 7 def main():
 8     setup(800,600)
 9     speed(10)
10     n=10
11     for i in range(n):
12         square(80)
13         left(360/n)
14     hideturtle()
15     done()
16 if __name__ == '__main__':
17     main()

 1 from turtle import *
 2 setup(800, 600)
 3 pencolor('pink')
 4 
 5 n = 10
 6 for i in range(n):
 7     # 绘制一片花瓣
 8     for j in range(2):
 9         circle(80, 90)
10         left(90)
11 
12     right(360/n)
13 
14 hideturtle()
15 done()

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

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

 

posted @ 2022-06-13 23:21  宋烨  阅读(6)  评论(2编辑  收藏  举报