task1_1
1 from turtle import * 2 3 4 def move(x, y): 5 penup() 6 goto(x, y) 7 pendown() 8 9 10 def draw(n, size=100): 11 for i in range(n): 12 fd(size) 13 left(360/n) 14 15 16 def main(): 17 pensize(2) 18 pencolor('red') 19 20 move(-200, 0) 21 draw(3) 22 23 move(0, 0) 24 draw(4) 25 26 move(200, 0) 27 draw(5) 28 29 hideturtle() 30 done() 31 32 33 main()
task1_2
1 from turtle import * 2 3 4 def moveto(x, y): 5 penup() 6 goto(x, y) 7 pendown() 8 9 10 def main(): 11 pensize(2) 12 pencolor('blue') 13 14 moveto(-150, 0) 15 circle(50) 16 17 moveto(0, 0) 18 circle(50, steps=4) 19 20 moveto(150, 0) 21 circle(50, steps=5) 22 23 moveto(300, 0) 24 circle(50, steps=6) 25 26 hideturtle() 27 done() 28 29 30 main()
实验2
task2_1
1 from turtle import * 2 3 4 def moveto(x, y): 5 penup() 6 goto(x, y) 7 pendown() 8 9 10 def main(): 11 setup(800, 600) 12 13 radius = 20 # 圆初始半径 14 offset = 20 # 同心圆每次位移量 15 16 for i in range(9): 17 moveto(0, -radius) 18 circle(radius) 19 radius += offset 20 21 hideturtle() 22 done() 23 24 25 main() 复制代码
task2_2
1 from turtle import * 2 from random import random 3 4 5 def moveto(x, y): 6 penup() 7 goto(x, y) 8 pendown() 9 10 11 def gen_color(): 12 return tuple((random() for i in range(3))) 13 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 35 main()
实验任务3:
task3_1
1 from turtle import * 2 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 16 def main(): 17 setup(800, 600) 18 speed(0) 19 20 n = 10 21 for i in range(n): 22 square(80, rgb='orange') 23 left(360/n) 24 25 hideturtle() 26 done() 27 28 29 main()
task3_2
1 from turtle import * 2 3 speed(0) 4 setup(800, 600) 5 pencolor('pink') 6 7 n = 10 8 for i in range(10): 9 # 绘制一片花瓣 10 for j in range(2): 11 circle(80, 90) 12 left(90) 13 14 right(360/n) 15 16 hideturtle() 17 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 from turtle import * 2 3 4 def moveto(x, y): 5 penup() 6 goto(x, y) 7 pendown() 8 9 10 setup(800, 600) 11 speed(0) 12 moveto(-100, -100) 13 14 15 def fill_square(rgb, sl): 16 fillcolor(rgb) 17 begin_fill() 18 for i in range(4): 19 fd(sl) 20 left(90) 21 end_fill() 22 hideturtle() 23 24 25 fill_square('black', 200) 26 27 moveto(0, -100) 28 left(45) 29 fill_square('red', 100*2**0.5) 30 31 done()
1 from turtle import * 2 3 setup(400, 400) 4 pencolor('blue') 5 pensize(2) 6 speed(0) 7 8 9 def func(n, r): 10 for i in range(n): 11 fd(r) 12 left(90) 13 circle(r, 90) 14 left(90) 15 fd(r) 16 left(90) 17 r += 20 18 19 20 func(5, 40) 21 hideturtle() 22 done() 复制代码
实验任务6:
task6_1
1 from turtle import * 2 from random import random 3 4 setup(800, 600) 5 speed(0) 6 penup() 7 goto(-200, 0) 8 pendown() 9 10 11 def get_color(): 12 return tuple(random() for i in range(3)) 13 14 15 def rect(width, length): 16 for i in range(20): 17 rgb = get_color() 18 pencolor(rgb) 19 fillcolor(rgb) 20 begin_fill() 21 fd(width) 22 left(90) 23 fd(length) 24 left(90) 25 fd(width) 26 left(90) 27 fd(length) 28 left(90) 29 end_fill() 30 fd(width) 31 32 33 rect(20, 80) 34 hideturtle() 35 done() 复制代码
1 from turtle import * 2 3 setup(600, 600) 4 bgcolor('black') 5 fillcolor('yellow') 6 speed(0) 7 8 begin_fill() 9 left(45) 10 fd(120) 11 left(90) 12 circle(120, 270) 13 left(90) 14 fd(120) 15 end_fill() 16 17 18 def moveto(x, y): 19 penup() 20 goto(x, y) 21 pendown() 22 23 24 def fill_circle(r, rgb): 25 fillcolor(rgb) 26 begin_fill() 27 left(180) 28 circle(r) 29 end_fill() 30 31 32 moveto(0, 60) 33 fill_circle(10, 'black') 34 35 moveto(8, 74) 36 fill_circle(4, 'white') 37 38 39 hideturtle() 40 done()
标签:turtle,10,moveto,20,python,绘图,fill,def,left From: https://www.cnblogs.com/hegejiushishiwo/p/17472984.html