1、实验任务1
task1_1.py
实验源码:
1 from turtle import * 2 3 def move(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 def draw(n,size = 100): 9 for i in range(n): 10 fd(size) 11 left(360/n) 12 13 def main(): 14 pensize(2) 15 pencolor('red') 16 17 move(-200,0) 18 draw(3) 19 20 move(0,0) 21 draw(4) 22 23 move(200,0) 24 draw(5) 25 26 hideturtle() 27 done() 28 29 main()
运行测试截图:
task1_2.py
实验源码:
1 from turtle import * 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 def main(): 9 pensize(2) 10 pencolor('blue') 11 12 moveto(-150,0) 13 circle(50) 14 15 moveto(0,0) 16 circle(50,steps=4) 17 18 moveto(150,0) 19 circle(50,steps=5) 20 21 moveto(300,0) 22 circle(50,steps=6) 23 24 hideturtle() 25 done() 26 27 main()
运行测试截图:
2、实验任务2
task2_1.py
实验源码:
1 from turtle import * 2 def moveto(x,y): 3 penup() 4 goto(x,y) 5 pendown() 6 7 def main(): 8 setup(800,600) 9 10 radius = 20 11 offset = 20 12 13 for i in range(9): 14 moveto(0,-radius) 15 circle(radius) 16 radius += offset 17 18 hideturtle() 19 done() 20 21 main()
运行测试截图:
task2_2.py
实验源码:
1 from turtle import * 2 from random import random 3 4 5 def moveto(x,y): 6 penup() 7 goto(x, y) 8 pendown() 9 10 11 def gen_color(): 12 return tuple((random() for i in range(3))) 13 14 15 def main(): 16 setup(800, 600) 17 18 radius = 180 19 offset = 20 20 21 for i in range(8): 22 moveto(0, -radius) 23 color(gen_color()) 24 25 begin_fill() 26 circle(radius) 27 end_fill() 28 29 radius -= offset 30 31 hideturtle() 32 done() 33 34 35 main()
运行测试截图:
3、实验任务3
用矩形绘制花瓣
实验源码:
1 from turtle import * 2 3 def square(size = 50, rgb = 'pink'): 4 pencolor(rgb) 5 for i in range(4): 6 fd(size) 7 left(90) 8 9 def main(): 10 setup(800,600) 11 speed(0) 12 13 n = 3 14 for i in range(n): 15 square(80) 16 left(360/n) 17 18 hideturtle() 19 done() 20 21 main()
运行测试截图:
task3_1.py
实验源码:
1 from turtle import * 2 3 def square(size = 50, rgb = 'yellow'): 4 pencolor(rgb) 5 for i in range(4): 6 fd(size) 7 left(90) 8 9 def main(): 10 setup(800,600) 11 speed(0) 12 13 n = 10 14 for i in range(n): 15 square(80) 16 left(360/n) 17 18 hideturtle() 19 done() 20 21 main()
运行测试截图:
task3_2.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()
运行测试截图:
4、实验任务4
task4.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 = 5 12 count = 50 13 for i in range(count): 14 fd(size) 15 angle +=360/n 16 seth(angle) 17 size+=5 18 19 hideturtle() 20 done()
运行测试截图:
5、实验任务5
task5_1.py
实验源码:
1 from turtle import * 2 penup() 3 goto(-100,-100) 4 pendown() 5 color('black') 6 begin_fill() 7 for i in range(4): 8 fd(200) 9 left(90) 10 end_fill() 11 penup() 12 goto(-100,0) 13 pendown() 14 seth(45) 15 color('red') 16 begin_fill() 17 for i in range(4): 18 fd(100*(2**0.5)) 19 right(90) 20 end_fill() 21 done()
运行测试截图:
task5_2.py
实验源码:
1 from turtle import * 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 moveto(0,0) 8 pensize(2) 9 pencolor('blue') 10 11 def main(): 12 radius = 40 13 offset = 20 14 for i in range(5): 15 fd(radius) 16 left(90) 17 circle(radius, 90) 18 left(90) 19 fd(radius) 20 moveto(0,0) 21 seth(0) 22 radius+=offset 23 done() 24 main()
运行测试截图:
6、实验任务6
task6.py
实验源码:
1 from turtle import * 2 from random import random 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 def gen_color(): 8 return tuple((random() for i in range(3))) 9 10 11 setup(800,600) 12 a = 50 13 b = 25 14 moveto(-10*b,a/2) 15 for i in range(20): 16 color(gen_color()) 17 begin_fill() 18 fd(b) 19 right(90) 20 fd(a) 21 right(90) 22 fd(b) 23 right(90) 24 fd(a) 25 moveto(-10*b+i*b,a/2) 26 seth(0) 27 end_fill() 28 done()
运行测试截图:
标签:10,moveto,20,range,实验,main,def From: https://www.cnblogs.com/desire666/p/17459088.html