实验8 python库应用编程与体验
------------恢复内容开始------------
#task3.py from turtle import * def square(size=50, rgb='orange'): '''绘制正方形 参数size指定边长 参数rgb指定画笔颜色 如果没有给参数,采用默认值 ''' pencolor(rgb) for i in range(4): fd(size) left(90) def main(): setup(800, 600) speed(0) n = 10 for i in range(n): square(80) left(360/n) hideturtle() done() if __name__ == '__main__': main()
1 #task4.py 2 from turtle import * 3 4 setup(800, 600) 5 pencolor('pink') 6 speed(0) 7 n = 10 8 for i in range(n): 9 # 绘制一片花瓣 10 for j in range(2): 11 circle(80, 90) 12 left(90) 13 14 right(360/n) 15 16 hideturtle() 17 done()
1 #task5.py 2 from turtle import * 3 4 setup(800, 600) 5 bgcolor('black') 6 pencolor('white') 7 speed(0) 8 9 angle = 0 10 size = 2 11 12 n = 8 13 for i in range(n): 14 for j in range(5): 15 fd(size) 16 angle += 72 17 seth(angle) 18 size += 6 19 20 hideturtle() 21 done()
1 #task6.py 2 from turtle import * 3 from random import random 4 setup(800,600) 5 speed(0) 6 7 def rect(): 8 rgb = tuple(random() for i in range(3)) 9 color(rgb) 10 begin_fill() 11 for i in range(2): 12 fd(20) 13 left(90) 14 fd(50) 15 left(90) 16 end_fill() 17 goto(-11*20,0) 18 for i in range(20): 19 rect() 20 fd(20) 21 hideturtle() 22 done()