实验任务1
task1.1
实验源码
1 from turtle import * 2 def move(x, y): 3 penup() 4 goto(x, y) 5 pendown() 6 def draw(n, size = 100): 7 for i in range(n): 8 fd(size) 9 left(360/n) 10 def main(): 11 pensize(2) 12 pencolor('red') 13 move(-200, 0) 14 draw(3) 15 move(0, 0) 16 draw(4) 17 move(200, 0) 18 draw(5) 19 hideturtle() 20 done() 21 main()
运行测试截图
task1.2
实验源码
1 from turtle import * 2 def moveto(x, y): 3 penup() 4 goto(x, y) 5 pendown() 6 def main(): 7 pensize(2) 8 pencolor('blue') 9 moveto(-150, 0) 10 circle(50) 11 moveto(0, 0) 12 circle(50, steps = 4) 13 moveto(150, 0) 14 circle(50, steps = 5) 15 moveto(300, 0) 16 circle(50, steps = 6) 17 hideturtle() 18 done() 19 main()
运行测试截图
实验任务2
task2
实验源码
1 from turtle import * 2 def moveto(x, y): 3 penup() 4 goto(x, y) 5 pendown() 6 def main(): 7 setup(800, 600) 8 radius = 20 # 圆初始半径 9 offset = 20 # 同心圆每次位移量 10 for i in range(9): 11 moveto(0, -radius) 12 circle(radius) 13 radius += offset 14 hideturtle() 15 done() 16 main()
运行测试截图
task2.2
实验源码
1 from turtle import * 2 from random import random 3 def moveto(x, y): 4 penup() 5 goto(x, y) 6 pendown() 7 8 def gen_color(): 9 return tuple((random() for i in range(3))) 10 def main(): 11 setup(800,600) 12 radius = 20 # 圆初始半径 13 offset = 20 # 同心圆每次位移量 14 for i in range(9): 15 moveto(0, -radius) 16 color(gen_color()) 17 circle(radius) 18 radius += offset 19 hideturtle() 20 done() 21 main()
运行测试截图
实验任务3
task3.1
实验源码
1 from turtle import * 2 def square(size = 50, rgb = 'pink'): 3 4 pencolor(rgb) 5 for i in range(4): 6 fd(size) 7 left(90) 8 def main(): 9 setup(800, 600) 10 speed(0) 11 n = 10 12 for i in range(n): 13 square(80) 14 left(360/n) 15 hideturtle() 16 done() 17 main()
运行测试截图
task3.2
实验源码
1 from turtle import * 2 setup(800, 600) 3 pencolor('pink') 4 n = 10 5 for i in range(10): 6 # 绘制一片花瓣 7 for j in range(2): 8 circle(80, 90) 9 left(90) 10 right(360/n) 11 hideturtle() 12 done()
运行测试截图
实验任务4
task4
实验源码
1 from turtle import * 2 setup(800, 600) 3 bgcolor('black') 4 pencolor('white') 5 speed(0) 6 angle = 0 7 size = 2 8 n = 5 # 螺旋n边形 9 count = 50 # 循环次数 10 for i in range(count): 11 fd(size) 12 angle += 360/n 13 seth(angle) 14 size += 5 15 hideturtle() 16 done()
运行测试截图
实验任务5
task5.1
实验源码
1 from turtle import * 2 3 right(45) 4 penup() 5 goto(-100,-100) 6 pendown() 7 begin_fill() 8 pencolor('black') 9 fillcolor('black') 10 circle(100*2**0.5,steps = 4) 11 end_fill() 12 13 left(45) 14 penup() 15 goto(0,-100) 16 pendown() 17 pensize(2) 18 pencolor('red') 19 begin_fill() 20 fillcolor('red') 21 circle(100,steps = 4) 22 end_fill() 23 24 hideturtle() 25 done()
运行测试截图
task5.2
实验源码
1 from turtle import * 2 3 pensize(2) 4 pencolor('blue') 5 for i in range(5): 6 setheading(90) 7 r = 40+20*i 8 goto(r,0) 9 circle(r,extent = 90) 10 goto(0,0) 11 hideturtle() 12 done()
运行测试截图
实验任务6
task6
实验源码
1 from turtle import * 2 from random import random 3 4 setup(800,600) 5 def gen_color(): 6 return tuple((random() for i in range(3))) 7 def rectangle(): 8 color(gen_color()) 9 begin_fill() 10 for i in range(2): 11 forward(5) 12 left(90) 13 forward(20) 14 left(90) 15 end_fill() 16 penup() 17 goto(-10*5,0) 18 pendown() 19 for k in range(20): 20 rectangle() 21 forward(5) 22 23 hideturtle() 24 done()
运行测试截图
标签:10,20,range,源码,实验,import,def From: https://www.cnblogs.com/siyi5981/p/17474870.html