task3.py
 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()

 

 

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     # 绘制一片花瓣
 9     for j in range(2):
10         circle(80, 90)
11         left(90)
12 
13     right(360/n)
14 
15 hideturtle()
16 done()

 

 

task5.py

from turtle import *

setup(800, 600)
bgcolor('black')
pencolor('white')
speed(0)

angle = 0
size = 2

n = 20
for i in range(n):
    for j in range(4):
        fd(size)
        angle += 72
        seth(angle)
        size += 5

hideturtle()
done()

 

 

task6.py

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