实验任务一
task1_1
实验源码:
1 from turtle import * 2 3 def move(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 def draw(n,size=100):#绘制边长为size的正n边形 8 for i in range(n): 9 fd(size) 10 left(360/n) 11 def main(): 12 pensize(2) 13 pencolor('red') 14 15 move(-200,0) 16 draw(3) 17 18 move(0,0) 19 draw(4) 20 21 move(200,0) 22 draw(5) 23 24 hideturtle() 25 done() 26 27 main()
实验结果截图:
task1_2
实验源码:
1 from turtle import * 2 3 def moveto(x,y):#circle()函数,实现正多边形绘制 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()
实验结果截图:
实验任务二
task2_1
实验源码:
1 from turtle import * 2 #使用turtle绘制九个同心圆 3 def moveto(x,y): 4 5 penup() 6 goto(x,y) 7 pendown() 8 9 def main(): 10 setup(800,600) 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
实验源码:
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():#生成一个以RGB三元组表示颜色值并返回 10 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()
实验结果截图:
实验任务三
task3_1
实验源码:
1 from turtle import * 2 def square(size = 50, rgb = 'pink'): 3 '''绘制正方形 4 :para: size:int 指定边长 (如未指定参数,使用默认值) 5 :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值)''' 6 pencolor(rgb) 7 for i in range(4): 8 fd(size) 9 left(90) 10 def main(): 11 setup(800, 600) 12 speed(0) 13 n = 3 14 for i in range(n): 15 square(80) 16 left(360/n) 17 hideturtle() 18 done() 19 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 fillcolor('red') 9 begin_fill() 10 circle(80, 90) 11 left(90) 12 end_fill() 13 right(360/n) 14 penup() 15 goto(0,-20) 16 pendown() 17 fillcolor('yellow') 18 begin_fill() 19 circle(20) 20 end_fill() 21 penup() 22 goto(0,-10) 23 pendown() 24 fillcolor('white') 25 begin_fill() 26 circle(10) 27 end_fill() 28 hideturtle() 29 done()
实验结果截图:
实验任务四
实验源码:
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 = 4 # 螺旋n边形 9 count = 50 # 循环次数 10 for i in range(count): 11 fd(size) 12 angle += 360/n + 1 13 seth(angle)#seth(角度(可以是整点数,也可以是浮点数))可以使龟逆时针旋转一定的角度,然后运动 14 size += 5 15 hideturtle() 16 done()
实验结果截图:
实验任务五
task5_1
实验源码:
1 from turtle import * 2 square = Turtle() 3 square.color('black') 4 square.penup() 5 square.goto(-100,-100) 6 7 square.pendown() 8 square.begin_fill() 9 for _ in range(4): 10 square.fd(200) 11 square.left(90) 12 square.end_fill() 13 14 15 s2 = Turtle() 16 s2.color('red') 17 s2.penup() 18 s2.goto(0,-100) 19 20 s2.pendown() 21 s2.left(45) 22 s2.begin_fill() 23 for _ in range(4): 24 s2.fd(100*(2**0.5)) 25 s2.left(90) 26 s2.end_fill() 27 done()
实验结果截图:
task5_2
1 from turtle import * 2 sector = Turtle() 3 # 初始化绘图参数 4 sector.penup() 5 sector.goto(0, 0) 6 sector.color('blue') 7 sector.pensize(2) 8 sector.speed(0) 9 # 设置扇形数值 10 radius = 40 11 delta_d = 20 12 sector.pendown() 13 for _ in range(5): 14 sector.fd(radius) 15 sector.left(90) 16 sector.circle(radius, extent=90) 17 sector.seth(270) 18 sector.fd(radius) 19 sector.seth(0) 20 21 radius += delta_d 22 23 done()
实验结果截图:
实验任务六
实验源码:
1 from turtle import * 2 from random import random 3 strip = Turtle() 4 setup(800, 600) 5 strip.speed(0) 6 # 获取颜色 7 8 9 def colors(): 10 return tuple(random() for _ in range(3)) 11 12 13 strip.pendown() 14 for i in range(10): 15 strip.color(colors()) 16 strip.begin_fill() 17 for _ in range(2): 18 strip.fd(20) 19 strip.left(90) 20 strip.fd(60) 21 strip.left(90) 22 strip.fd(20) 23 strip.end_fill() 24 25 strip.penup() 26 strip.goto(0, 0) 27 strip.pendown() 28 29 for i in range(10): 30 strip.color(colors()) 31 strip.begin_fill() 32 strip.seth(180) 33 for _ in range(2): 34 strip.fd(20) 35 strip.right(90) 36 strip.fd(60) 37 strip.right(90) 38 strip.fd(20) 39 strip.end_fill() 40 strip.hideturtle() 41 done()
实验结果截图:
标签:10,20,range,实验,strip,fill From: https://www.cnblogs.com/wjh857925263/p/17472917.html