实验任务1
task1_1
1 from turtle import * 2 3 def moveto(x,y): 4 ''' 5 画笔移动到坐标(x,y)处 6 ''' 7 penup() 8 goto(x,y) 9 pendown() 10 11 def draw(n,size = 100): 12 ''' 13 绘制边长为size的正n边形 14 ''' 15 for i in range(n): 16 fd(size) 17 left(360/n) 18 19 def main(): 20 pensize(2) 21 pencolor('red') 22 23 moveto(-200,0) 24 draw(3) 25 26 moveto(0,0) 27 draw(4) 28 29 moveto(200,0) 30 draw(5) 31 32 hideturtle() 33 done() 34 35 main()
task1_2
1 # 运用circle函数,实现正多边形绘制 2 from turtle import * 3 4 def moveto(x,y): 5 ''' 6 画笔移动到坐标(x,y)处 7 ''' 8 penup() 9 goto(x,y) 10 pendown() 11 12 def main(): 13 pensize(2) 14 pencolor('blue') 15 16 moveto(-150,0) 17 circle(50) 18 19 moveto(0,0) 20 circle(50,steps = 4) 21 22 moveto(150,0) 23 circle(50,steps = 5) 24 25 moveto(300,0) 26 circle(50,steps = 6) 27 28 hideturtle() 29 done() 30 31 main()
实验任务2
task2_1
1 # 用turtle绘制9个同心圆 2 from turtle import * 3 4 def moveto(x,y): 5 penup() 6 goto(x,y) 7 pendown() 8 9 def main(): 10 setup(800,600) 11 12 radius = 20 # 圆初始半径 13 offset = 20 # 同心圆每次位移量 14 15 for i in range(9): 16 moveto(0,-radius) 17 circle(radius) 18 radius += offset 19 20 hideturtle() 21 done() 22 23 main()
task2_2_1
1 # 以(0, 0)为圆心,绘制9个彩色同心圆,色彩随机生成 2 from turtle import * 3 from random import random 4 5 def moveto(x, y): 6 penup() 7 goto(x, y) 8 pendown() 9 10 def gen_color(): 11 ''' 12 生成一个以rgb三元组表示的颜色值并返回 13 ''' 14 return tuple((random() for i in range(3))) 15 16 def main(): 17 setup(800, 600) 18 radius = 180 # 圆初始半径 19 offset = 20 # 同心圆每次位移量 20 for i in range(8): 21 moveto(0, -radius) 22 color(gen_color()) 23 begin_fill() 24 circle(radius) 25 end_fill() 26 27 radius -= offset 28 29 hideturtle() 30 done() 31 32 main()
颜色随机变化
task2_2_2
1 # 以(0, 0)为圆心,绘制9个彩色同心圆,色彩随机生成 2 from turtle import * 3 from random import random 4 5 def moveto(x, y): 6 penup() 7 goto(x, y) 8 pendown() 9 10 def gen_color(): 11 ''' 12 生成一个以rgb三元组表示的颜色值并返回 13 ''' 14 return tuple((random() for i in range(3))) 15 16 def main(): 17 setup(800, 600) 18 radius = 20 # 圆初始半径 19 offset = 20 # 同心圆每次位移量 20 for i in range(8): 21 moveto(0, -radius) 22 color(gen_color()) 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 # 用矩形绘制花瓣 2 from turtle import * 3 4 def square(size = 50, rgb = 'pink'): 5 ''' 6 绘制正方形 7 :para: size:int 指定边长 (如未指定参数,使用默认值) 8 :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值) 9 ''' 10 pencolor(rgb) 11 for i in range(4): 12 fd(size) 13 left(90) 14 15 def main(): 16 setup(800, 600) 17 speed(0) 18 19 n = 3 20 for i in range(n): 21 square(80) 22 left(360/n) 23 24 hideturtle() 25 done() 26 27 main()
# 用矩形绘制花瓣 from turtle import * def square(size = 50, rgb = 'pink'): ''' 绘制正方形 :para: size:int 指定边长 (如未指定参数,使用默认值) :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值) ''' pencolor(rgb) for i in range(4): fd(size) left(90) def main(): setup(800, 600) speed(0) n = 4 for i in range(n): square(80) left(360/n) hideturtle() done() main()
1 # 用矩形绘制花瓣 2 from turtle import * 3 4 def square(size = 50, rgb = 'pink'): 5 ''' 6 绘制正方形 7 :para: size:int 指定边长 (如未指定参数,使用默认值) 8 :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值) 9 ''' 10 pencolor(rgb) 11 for i in range(4): 12 fd(size) 13 left(90) 14 15 def main(): 16 setup(800, 600) 17 speed(0) 18 19 n = 5 20 for i in range(n): 21 square(80) 22 left(360/n) 23 24 hideturtle() 25 done() 26 27 main()
n=6
n=10
task3_2
1 from turtle import * 2 3 setup(800, 600) 4 pencolor('pink') 5 6 n = 10 7 for i in range(n): 8 # 绘制一片花瓣 9 for j in range(2): 10 circle(80, 90) 11 left(90) 12 13 right(360/n) 14 15 hideturtle() 16 done()
实验任务4
task4
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 # 螺旋n边形 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()
实验任务5
task5_1
1 # 先画外围正方形 2 from turtle import * 3 4 def moveto(x, y): 5 penup() 6 goto(x, y) 7 pendown() 8 9 color('black') 10 begin_fill() 11 moveto(-100,-100) 12 for i in range(4): 13 fd(200) 14 left(90) 15 end_fill() 16 17 # 再画内三角形 18 color('red') 19 20 begin_fill() 21 moveto(0,-100) 22 left(45) 23 for i in range(4): 24 fd(100*2**(1/2)) 25 left(90) 26 end_fill() 27 hideturtle() 28 done()
task5_2
1 size = 5 2 color('blue') 3 4 radius = 40 5 for i in range(5): # 扇形的个数 6 fd(radius) 7 left(90) 8 circle(radius,90) 9 left(90) 10 fd(radius) 11 left(90) 12 radius += 20 13 14 hideturtle() 15 done()
实验任务6
1 from turtle import * 2 screensize(100,100,'black') 3 4 def moveto(x, y): 5 penup() 6 goto(x, y) 7 pendown() 8 9 # 画脸 10 color('yellow') 11 begin_fill() 12 left(45) 13 fd(100) 14 left(90) 15 circle(100,270) 16 left(90) 17 fd(100) 18 end_fill() 19 20 # 画眼睛 21 moveto(10,65) 22 dot(15,'black') 23 24 # 画高光 25 moveto(8,70) 26 dot(8,'white') 27 28 hideturtle() 29 done()
标签:turtle,moveto,20,python,range,绘图,radius,def,left From: https://www.cnblogs.com/xixihamugua/p/17459308.html