任务一
实验源码
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()task
运行结果截图
实验源码
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()task
任务二
实验源码
1 '''以(0,0)为圆心,绘制9个同心圆''' 2 3 from turtle import * 4 5 def moveto(x, y): 6 penup() 7 goto(x, y) 8 pendown() 9 10 def main(): 11 setup(800, 600) 12 13 radius = 20 14 offset = 20 # 同心圆每次位移量 15 for i in range(9): 16 moveto(0, -radius) 17 circle(radius) 18 radius += offset 19 20 hideturtle() 21 done() 22 23 main()task
运行结果截图
实验源码
1 '''以(0, 0)为圆心,绘制9个彩色同心圆,色彩随机生成''' 2 3 from turtle import * 4 from random import random 5 6 def moveto(x, y): 7 penup() 8 goto(x, y) 9 pendown() 10 11 def gen_color(): 12 '''生成一个以rgb三元组表示的颜色值并返回''' 13 return tuple((random() for i in range(3))) 14 15 def main(): 16 setup(800, 600) 17 18 radius=180 19 offset=20 20 21 for i in range(8): 22 moveto(0, -radius) 23 color(gen_color()) 24 25 begin_fill() 26 circle(radius) 27 end_fill() 28 29 radius -= offset 30 31 hideturtle() 32 done() 33 34 main()task
运行结果截图
任务三
实验源码
1 from turtle import * 2 3 def square(size=50, rgb='pink'): 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 = 3 19 for i in range(n): 20 square(80) 21 left(360/n) 22 23 hideturtle() 24 done() 25 26 main()task
运行结果截图
实验源码
1 from turtle import * 2 3 def square(size=50, rgb='pink'): 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 def trangle(size=50): 14 for i in range(3): 15 fd(size) 16 left(120) 17 18 19 20 setup(800, 600) 21 speed(0) 22 n = 10 23 for i in range(n): 24 square(80) 25 left(360/n) 26 27 28 29 hideturtle() 30 done()task
运行结果截图
实验源码
1 from turtle import * 2 3 setup(800, 600) 4 pencolor('pink') 5 speed(0) 6 7 n=10 8 for i in range(n): 9 for i in range(2): 10 circle(80, 90) 11 left(90) 12 13 right(360/n) 14 15 hideturtle() 16 done()task
运行结果截图
任务四
实验源码
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 = 4 # 螺旋n边形 12 count = 50 13 for i in range(count): 14 fd(size) 15 angle += 360/n+1 16 seth(angle) 17 size += 5 18 19 hideturtle() 20 done()task
运行结果截图
任务五
实验源码
1 from turtle import * 2 def square(size): 3 for i in range(4): 4 fd(size) 5 left(90) 6 7 8 9 penup() 10 goto(-100, -100) 11 pendown() 12 begin_fill() 13 fillcolor('black') 14 square(200) 15 end_fill() 16 17 penup() 18 goto(0, -100) 19 pendown() 20 left(45) 21 begin_fill() 22 fillcolor('red') 23 square(100*(2**0.5)) 24 end_fill() 25 26 hideturtle() 27 done()task
运行结果截图
实验源码
1 from turtle import * 2 3 pensize(2) 4 pencolor('blue') 5 6 radius = 40 7 offset = 20 8 9 for i in range(5): 10 home() 11 setheading(0) 12 forward(radius) 13 left(90) 14 circle(radius, 90) 15 left(90) 16 forward(radius) 17 radius += offset 18 19 done()task
运行结果截图
任务六
实验源码
1 from turtle import * 2 def moveto(x, y): 3 penup() 4 goto(x, y) 5 pendown() 6 7 bgcolor('black') 8 pencolor('yellow') 9 begin_fill() 10 fillcolor('yellow') 11 goto(100, 100) 12 left(135) 13 circle(100*2**0.5, 270) 14 end_fill() 15 16 pencolor('black') 17 begin_fill() 18 fillcolor('black') 19 20 moveto(0, 80) 21 circle(15) 22 end_fill() 23 24 moveto(-15, 90) 25 begin_fill() 26 fillcolor('white') 27 circle(5) 28 end_fill() 29 30 hideturtle() 31 done()task
运行结果截图
标签:10,20,range,radius,实验,def,size From: https://www.cnblogs.com/sqdl666/p/17474721.html