实验八

 task3

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

 

 

task4

1
from turtle import* 2 3 4 setup(800,600) 5 pencolor('pink') 6 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 17 hideturtle() 18 done()

 

 

 

task5

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

 

 

 

task6

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

 

 

posted on 2022-06-14 10:58  张玮珊  阅读(8)  评论(1编辑  收藏  举报