实验任务1 task1_1.py
1 from turtle import * 2 def move(x, y): 3 '''画笔移动到坐标(x,y)处''' 4 penup() 5 goto(x, y) 6 pendown() 7 8 def draw(n, size = 100): 9 '''绘制边长为size的正n变形''' 10 for i in range(n): 11 fd(size) 12 left(360/n) 13 14 def main(): 15 pensize(2) 16 pencolor('red') 17 18 move(-200, 0) 19 draw(3) 20 21 move(0, 0) 22 draw(4) 23 24 move(200, 0) 25 draw(5) 26 27 hideturtle() 28 done() 29 30 31 main()
task1_2.py
1 from turtle import * 2 3 def moveto(x, y): 4 '''把画笔移动至坐标(x, y)处''' 5 penup() 6 goto(x, y) 7 pendown() 8 9 def main(): 10 pensize(2) 11 pencolor('blue') 12 13 moveto(-150, 0) 14 circle(50) 15 16 moveto(0, 0) 17 circle(50, steps = 4) 18 19 moveto(150, 0) 20 circle(50, steps = 5) 21 22 moveto(300, 0) 23 circle(50, steps = 6) 24 25 hideturtle() 26 done() 27 28 main()
实验任务2 task2_1.py
1 '''以(0,0)为圆心,绘制9个同心圆''' 2 3 from turtle import * 4 5 def moveto(x, y): 6 '''把画笔移至坐标(x,y)处''' 7 penup() 8 goto(x, y) 9 pendown() 10 11 12 def main(): 13 setup(800, 600) 14 15 radius = 20 # 圆初始半径 16 offset = 20 # 同心圆每次位移量 17 18 for i in range(9): 19 moveto(0, -radius) 20 circle(radius) 21 radius += offset 22 23 hideturtle() 24 done() 25 26 main()
task2_2.py
1 '''以(0, 0)为圆心,绘制9个彩色同心圆,色彩随机生成''' 2 from turtle import * 3 from random import random 4 5 def moveto(x, y): 6 '''把画笔移至坐标(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()
实验任务3 task3_1.py
1 from turtle import* 2 def squre(size=50,rgb='pink'): 3 pencolor(rgb) 4 for i in range(4): 5 fd(size) 6 left(90) 7 def main(): 8 setup(800,600) 9 speed(0) 10 n=9 11 for i in range(n): 12 squre(80) 13 left(360/n) 14 hideturtle() 15 done() 16 main()
task3_2.py
1 from turtle import* 2 setup(800,600) 3 pencolor('pink') 4 n=10 5 for i in range(10): 6 for j in range(2): 7 circle(80,90) 8 left(90) 9 right(360/n) 10 hideturtle() 11 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 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 def move(x,y): 3 penup() 4 goto(x,y) 5 pendown() 6 move(-100,0) 7 begin_fill() 8 for i in range(4): 9 fd(200) 10 left(90) 11 end_fill() 12 move(0,0) 13 begin_fill() 14 pencolor('red') 15 fillcolor('red') 16 left(45) 17 for i in range(4): 18 fd(100*2**0.5) 19 left(90) 20 end_fill() 21 hideturtle() 22 done()task5_2.py
1 from turtle import * 2 def move(x,y): 3 penup() 4 goto(x,y) 5 pendown() 6 pensize(2) 7 pencolor('blue') 8 speed(0) 9 r = 40 10 move(0,-r) 11 for i in range(5): 12 circle(r) 13 r+=20 14 move(0,-r) 15 move(-120,0) 16 begin_fill() 17 fillcolor('white') 18 pencolor('white') 19 for i in range(4): 20 fd(120) 21 left(90) 22 end_fill() 23 move(-120,-120) 24 begin_fill() 25 fillcolor('white') 26 pencolor('white') 27 for i in range(4): 28 fd(120) 29 left(90) 30 end_fill() 31 move(0,-120) 32 begin_fill() 33 fillcolor('white') 34 pencolor('white') 35 for i in range(4): 36 fd(120) 37 left(90) 38 end_fill() 39 pencolor('blue') 40 move(0,0) 41 fd(120) 42 move(0,0) 43 left(90) 44 fd(120) 45 hideturtle() 46 done()
实验任务6
1 from turtle import * 2 3 setup(800,600) 4 speed(0) 5 6 def move(x,y): 7 penup() 8 goto(x,y) 9 pendown() 10 11 bgcolor('black') 12 13 move(0,-100) 14 pencolor('yellow') 15 fillcolor('yellow') 16 begin_fill() 17 circle(100) 18 end_fill() 19 20 pencolor('black') 21 move(0,0) 22 begin_fill() 23 fillcolor('black') 24 right(45) 25 for i in range(4): 26 fd(100) 27 left(90) 28 29 move(0,50) 30 circle(16) 31 end_fill() 32 33 pencolor('white') 34 fillcolor('white') 35 begin_fill() 36 move(-4*2**0.5,50+4*2**0.5) 37 circle(4) 38 end_fill() 39 40 hideturtle() 41 done()
标签:20,move,pencolor,range,实验,def,fill From: https://www.cnblogs.com/zjyuan1013/p/17458540.html