实验任务1
task1_1.py
程序源码:
1 from turtle import * 2 3 def move(x, y):#画笔移动到坐标(x,y)处 4 penup() 5 goto(x, y) 6 pendown() 7 8 def draw(n, size = 100):#绘制边长为size的正n变形 9 for i in range(n): 10 forward(size) 11 left(360/n) 12 13 def main(): 14 pensize(2) 15 pencolor('red') 16 move(-200, 0) 17 draw(3) 18 move(0, 0) 19 draw(4) 20 move(200, 0) 21 draw(5) 22 hideturtle() 23 done() 24 main()
运行测试截图:
task1_2.py
程序源码:
1 from turtle import* 2 3 def moveto(x,y):#把画笔移动到坐标(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()
运行测试截图:
实验任务2
task2_1.py
程序源码:
1 '''以(0,0)为圆心,绘制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.py
程序源码:
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 return tuple(random() for i in range(3)) 13 14 def main(): 15 setup(800,600) 16 17 radius=180 18 offset=20 19 20 for i in range(8): 21 moveto(0,-radius) 22 color(gen_color()) 23 24 begin_fill() 25 circle(radius) 26 end_fill() 27 28 radius-=offset 29 30 hideturtle() 31 done() 32 33 main()
运行测试截图:
实验任务3
task3_1.py
程序源码:
1 from turtle import * 2 3 def square(size=50,rbg='pink'): 4 '''绘制正方形 5 :para: size:int 指定边长 (如未指定参数,使用默认值) 6 :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值) 7 ''' 8 9 pencolor(rbg) 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=10 19 for i in range(n): 20 square(80) 21 left(360/n) 22 23 hideturtle() 24 done() 25 26 main()
运行测试截图:
task3_2.py
程序源码:
1 from turtle import * 2 3 setup(800,600) 4 pencolor('pink') 5 speed(0) 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()
运行测试截图:
实验任务4
task4.py
程序源码:
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.py
程序源码:
1 from turtle import * 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 def square(): 9 for i in range(4): 10 fd(200) 11 left(90) 12 def main(): 13 moveto(-100, -100) 14 color('black') 15 begin_fill() 16 square() 17 end_fill() 18 19 moveto(0, -100) 20 color('red') 21 begin_fill() 22 circle(100, steps=4) 23 end_fill() 24 25 hideturtle() 26 done() 27 28 main()
运行测试截图:
task5_2.py
程序源码:
1 from turtle import * 2 3 pensize(2) 4 pencolor('blue') 5 6 def main(): 7 for i in range(5): 8 fd(40+20*i) 9 left(90) 10 circle(40+20*i,90) 11 left(90) 12 fd(40+20*i) 13 left(90) 14 15 hideturtle() 16 done() 17 18 main()
运行测试截图:
实验任务6
task6.py
程序源码:
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 square(): 13 color(gen_color()) 14 begin_fill() 15 for i in range(2): 16 fd(10) 17 left(90) 18 fd(25) 19 left(90) 20 end_fill() 21 22 setup(800,600) 23 24 moveto(-50,0) 25 for i in range(20): 26 square() 27 fd(10) 28 29 hideturtle() 30 done()
运行测试截图:
标签:turtle,10,moveto,20,python,range,绘图,main,def From: https://www.cnblogs.com/cl040302/p/17473124.html