实验1
task1.1
实验源码
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()View Code
实验截图
task1.2
实验源码
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()View Code
实验截图
实验2
task2.1
实验源码
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()View Code
实验截图
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()View Code
实验截图
实验3
task3.1
实验源码
1 from turtle import* 2 3 def square(size = 50, rgb = 'pink'):#'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,'orange') 16 left(360/n) 17 18 hideturtle() 19 done() 20 main()View Code
实验截图
task3.2
实验源码
1 from turtle import* 2 3 speed = 0 4 setup(800,600) 5 pencolor('pink') 6 7 n = 10 8 for i in range(10): 9 for j in range(2): 10 circle(80,90) 11 left(90) 12 13 right(360/n) 14 15 hideturtle() 16 done()View Code
实验截图
实验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()View Code
实验截图
实验5
task5.1
实验源码
1 from turtle import* 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 setup(800,600) 9 speed = 0 10 moveto(-100,-100) 11 12 def square(size,rgb): 13 fillcolor(rgb) 14 begin_fill() 15 for i in range(4): 16 fd(size) 17 left(90) 18 end_fill() 19 20 21 square(200,'black') 22 23 moveto(0,-100) 24 left(45) 25 square(100*(2**0.5),'red') 26 27 hideturtle() 28 done()View Code
实验截图
task5.2
实验源码
1 from turtle import* 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 pencolor('blue') 9 pensize(2) 10 speed = 0 11 12 def main(): 13 setup(800,600) 14 15 radius = 40 16 offset = 20 17 18 for i in range(5): 19 moveto(0,0) 20 fd(radius) 21 left(90) 22 circle(radius,90) 23 left(90) 24 fd(radius) 25 left(90) 26 radius += 20 27 28 hideturtle() 29 done() 30 31 main()View Code
实验截图
实验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 def draw_ract(x,y,width,height): 13 moveto(x,y) 14 setheading(0) 15 for i in range(2): 16 forward(width) 17 left(90) 18 forward(height) 19 left(90) 20 21 for t in range(20): 22 x0 = -100 23 rgb = gen_color() 24 pencolor(rgb) 25 fillcolor(rgb) 26 begin_fill() 27 draw_ract(x0+10*t , 10,10,100) 28 end_fill() 29 30 hideturtle() 31 done()View Code
实验截图
task6.2
实验源码
1 from turtle import* 2 3 setup(800,600) 4 fillcolor('yellow') 5 bgcolor('black') 6 speed(0) 7 8 begin_fill() 9 left(45) 10 fd(150) 11 left(90) 12 circle(150,270) 13 left(90) 14 fd(150) 15 end_fill() 16 17 def moveto(x,y): 18 penup() 19 goto(x,y) 20 pendown() 21 22 moveto(4,70) 23 fillcolor('black') 24 begin_fill() 25 circle(10) 26 end_fill() 27 28 moveto(-4,70) 29 fillcolor('white') 30 begin_fill() 31 circle(3) 32 end_fill() 33 34 hideturtle() 35 done()View Code
实验截图
标签:10,20,range,实验,def,left From: https://www.cnblogs.com/bowen666666/p/17474759.html