实验任务1:使用turtle绘制基础图形
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 30 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:使用turtle绘制9个同心圆
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.py
实验源码:
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:使用turtle绘制花瓣效果
task3_1.py
实验源码:
1 from turtle import* 2 3 def square(size=50,rgb='orange'): 4 ''' 5 :para:size:int 6 :para:c:str 7 ''' 8 9 pencolor(rgb) 10 for i in range(4): 11 fd(size) 12 left(90) 13 14 def main(): 15 setup(800,600) 16 speed(0) 17 18 n=10 19 for i in range(n): 20 square(80) 21 left(360/n) 22 23 hideturtle() 24 done() 25 26 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 15 hideturtle() 16 done()
实验结果:
实验任务4:使用turtle绘制螺旋多边形
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:使用turtle绘制基础图形
task5_1.py
实验源码:
1 from turtle import * 2 3 4 def move(x,y): 5 penup() 6 goto(x,y) 7 pendown() 8 9 10 def draw(n,a,size = 100): 11 color(a) 12 begin_fill() 13 14 for i in range(n): 15 fd(size) 16 left(360/n) 17 end_fill() 18 19 20 move(-100,-100) 21 draw(4,'black',200) 22 move(-100,0) 23 right(45) 24 draw(4,'red',100*(2)**0.5) 25 26 27 hideturtle() 28 done()
实验结果:
task5_2.py
实验源码:
1 from turtle import * 2 3 4 pensize(2) 5 def move(x,y): 6 penup() 7 goto(x,y) 8 pendown() 9 10 def quarter_round(r): 11 pencolor('blue') 12 move(0,r) 13 circle(-r,90) 14 15 for i in range(2): 16 right(90) 17 fd(r) 18 home() 19 20 radius=40 21 offset=20 22 for i in range(5): 23 quarter_round(radius) 24 radius+=offset 25 26 27 hideturtle() 28 done()
实验结果:
实验任务6:绘图
task6.py
实验源码:
1 from turtle import * 2 3 def move(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 bgcolor('black') 9 color('yellow') 10 move(0,-100) 11 begin_fill() 12 circle(100) 13 end_fill() 14 color('black') 15 speed(0) 16 move(87,-51) 17 seth(60) 18 begin_fill() 19 circle(100,80) 20 home() 21 end_fill() 22 move(-30,60) 23 dot(30,'black') 24 move(-38,60) 25 dot(5,'white') 26 27 hideturtle() 28 done()
实验结果:
标签:turtle,10,20,python,move,实验,绘图,def From: https://www.cnblogs.com/gaoyue124/p/17458017.html