实验任务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
task2_1.py
源代码
1 from turtle import* 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 def main(): 9 setup(800,600) 10 11 radius=20 12 offset=20 13 14 for i in range(9): 15 moveto(0,-radius) 16 circle(radius) 17 radius+=offset 18 19 hideturtle() 20 done() 21 22 main()
运行截图
task2_2
源代码
1 from turtle import* 2 from random import random 3 4 def moveto(x,y): 5 penup() 6 goto(x,y) 7 pendown() 8 9 def gen_color(): 10 return tuple((random() for i in range(3))) 11 12 def main(): 13 setup(800,600) 14 15 radius=180 16 offset=20 17 18 for i in range(8): 19 moveto(0,-radius) 20 color(gen_color()) 21 22 begin_fill() 23 circle(radius) 24 end_fill() 25 26 radius-=offset 27 28 hideturtle() 29 done() 30 31 main()
运行截图
实验任务3
task3_1.py
源代码
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=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(10): 8 for j in range(2): 9 circle(80,90) 10 left(90) 11 12 right(360/n) 13 14 hideturtle() 15 done()
运行截图
实验任务4
源代码
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
task5_1.py
源代码
1 from turtle import* 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 color('black') 9 moveto(-100,-100) 10 begin_fill() 11 for i in range(4): 12 fd(200) 13 left(90) 14 end_fill() 15 16 color('red') 17 moveto(100,0) 18 begin_fill() 19 left(135) 20 for i in range(4): 21 fd(100*(2**0.5)) 22 left(90) 23 end_fill() 24 25 hideturtle() 26 down()
运行截图
task5_2.py
源代码
1 from turtle import* 2 3 pensize(2) 4 pencolor('blue') 5 speed=0 6 7 def moveto(x,y): 8 penup() 9 goto(x,y) 10 pendown() 11 12 13 x=0 14 for i in range(5): 15 moveto(40+x,0) 16 left(90) 17 circle(40+x,90) 18 left(90) 19 fd(40+x) 20 left(90) 21 fd(40+x) 22 x+=20 23 24 hideturtle() 25 down()
运行截图
实验任务6
task6_1
源代码
1 from turtle import* 2 from random import random 3 4 def moveto(x,y): 5 penup() 6 goto(x,y) 7 pendown() 8 9 def gen_color(): 10 return tuple((random() for i in range(3))) 11 12 setup(800,600) 13 x=0 14 for i in range(20): 15 moveto(-200+x,0) 16 begin_fill() 17 color(gen_color()) 18 for j in range(2): 19 fd(20) 20 left(90) 21 fd(60) 22 left(90) 23 end_fill() 24 x+=20 25 26 hideturtle() 27 done()
运行截图
task6_2
源代码
1 setup(800,600) 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 radius = 150 9 color('yellow') 10 begin_fill() 11 moveto(radius/2**0.5,radius/2**0.5) 12 left(135) 13 circle(150,360-90) 14 end_fill() 15 16 radius1 = 15 17 color('black') 18 begin_fill() 19 moveto(0,150/2) 20 circle(15) 21 end_fill() 22 23 radius2 = 5 24 color('white') 25 begin_fill() 26 moveto(-15,165/2) 27 circle(5) 28 end_fill() 29 30 hideturtle() 31 done()
运行截图
标签:turtle,10,moveto,20,Python,range,绘图,15,def From: https://www.cnblogs.com/zyj-/p/17458531.html