实验8 python库应用编程与体验

task3.py

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

task4.py

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

task5.py

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

task6.py

 1 from random import random
 2 from turtle import *
 3 
 4 def rect():
 5     rgb = tuple(random() for i in range(3))
 6     color(rgb)
 7     begin_fill()
 8     for i in range(2):
 9         fd(20)
10         left(90)
11         fd(60)
12         left(90)
13     end_fill()
14 
15 def main():
16     goto(-11*20, 0)
17     for i in range(20):
18         rect()
19         fd(20)
20 
21 setup(800, 600)
22 speed(0)
23 main()

 

实验总结:用python画图还是挺奇妙的(ps:倒数第二个一个图我看起来有点晕),不过有时候也有点转不过来弯,借鉴了一下大佬们的代码,膜拜大佬!

 

posted @ 2022-06-13 21:18  虞渊  阅读(9)  评论(2编辑  收藏  举报