实验任务1
task1:
1 from turtle import * 2 3 def move(x, y): 4 '''画笔移动到坐标(x,y)处''' 5 penup() 6 goto(x, y) 7 pendown() 8 9 def draw(n, size = 100): 10 '''绘制边长为size的正n边形''' 11 for i in range(n): 12 fd(size) 13 left(360/n) 14 15 def main(): 16 pensize(2) 17 pencolor('red') 18 19 move(-200, 0) 20 draw(3) 21 22 move(0, 0) 23 draw(4) 24 25 move(200, 0) 26 draw(5) 27 28 hideturtle() 29 done() 30 31 main()
运行结果:
task1_2:
1 from turtle import * 2 3 def moveto(x, y): 4 '''画笔移动到坐标(x,y)处''' 5 penup() 6 goto(x, y) 7 pendown() 8 9 10 def main(): 11 pensize(2) 12 pencolor('blue') 13 14 moveto(-150, 0) 15 circle(50) 16 17 moveto(0, 0) 18 circle(50,steps = 4) 19 20 moveto(150, 0) 21 circle(50, steps = 5) 22 23 moveto(300, 0) 24 circle(50, steps = 6) 25 26 hideturtle() 27 done() 28 29 main()
实验任务2
task2:
1 from turtle import * 2 3 def moveto(x, y): 4 '''画笔移动到坐标(x,y)处''' 5 penup() 6 goto(x, y) 7 pendown() 8 9 10 def main(): 11 setup(800, 600) 12 13 radius = 20 14 offset = 20 15 16 for i in range(9): 17 moveto(0, -radius) 18 circle(radius) 19 radius += offset 20 21 hideturtle() 22 done() 23 24 main()
运行结果:
task2_2:
1 from turtle import * 2 from random import random 3 4 def moveto(x, y): 5 '''画笔移动到坐标(x,y)处''' 6 penup() 7 goto(x, y) 8 pendown() 9 10 def gen_color(): 11 return tuple((random() for i in range(3))) 12 13 def main(): 14 setup(800, 600) 15 16 radius = 180 17 offset = 20 18 19 for i in range(8): 20 moveto(0, -radius) 21 color(gen_color()) 22 23 begin_fill() 24 circle(radius) 25 end_fill() 26 27 radius -= offset 28 29 hideturtle() 30 done() 31 32 main()
运行结果:
实验任务3
task3_1:
1 from turtle import * 2 3 def square(size = 50, rgb = 'pink'): 4 5 pencolor(rgb) 6 for i in range(4): 7 fd(size) 8 left(90) 9 10 def main(): 11 setup(800, 600) 12 speed(0) 13 14 n = 10 15 for i in range(n): 16 square(80) 17 left(360/n) 18 19 hideturtle() 20 done() 21 22 main()
运行结果:
task3_2:
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
task4:
1 from turtle import * 2 3 setup(1600,1200) 4 bgcolor('black') 5 pencolor('white') 6 speed(0) 7 8 angle=0 9 size=1 10 11 n=5 12 count=100 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:
1 from turtle import * 2 3 def move(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 def draw(n,c,size = 100): 9 color(c) 10 begin_fill() 11 12 for i in range(n): 13 fd(size) 14 left(360/n) 15 end_fill() 16 17 move(-100,-100) 18 draw(4,'black',200) 19 20 move(-100,0) 21 right(45) 22 draw(4,'red',100*(2)**0.5) 23 24 hideturtle() 25 done()
运行结果:
task5_2:
1 from turtle import * 2 3 pensize(2) 4 def move(x,y): 5 penup() 6 goto(x,y) 7 pendown() 8 def quarter_round(r): 9 pencolor('blue') 10 move(0,r) 11 circle(-r,90) 12 for i in range(2): 13 right(90) 14 fd(r) 15 home() 16 17 radius=40 18 offset=20 19 for i in range(5): 20 quarter_round(radius) 21 radius+=offset 22 hideturtle() 23 done()
运行结果:
实验任务6
task6:
1 from turtle import * 2 speed(0) 3 def move(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 bgcolor('black') 8 color('yellow') 9 move(0,-100) 10 begin_fill() 11 circle(100) 12 end_fill() 13 color('black') 14 move(87,-51) 15 seth(60) 16 begin_fill() 17 circle(100,60) 18 home() 19 end_fill() 20 move(-30,50) 21 dot(30,'black') 22 move(-38,58) 23 dot(5,'white') 24 hideturtle() 25 done()
运行结果:
标签:10,20,move,range,实验,radius,def From: https://www.cnblogs.com/gajs456asd5f4/p/17473493.html