1.实验任务1
task1_1.py
1 from turtle import * 2 3 def move(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 def draw(n,size = 100): 9 for i in range(n): 10 fd(size) 11 left(360/n) 12 13 def main(): 14 pensize(2) 15 pencolor('red') 16 17 move(-200,0) 18 draw(3) 19 20 move(0,0) 21 draw(4) 22 23 move(200,0) 24 draw(5) 25 26 hideturtle() 27 done() 28 29 30 main()
task1_2.py
1 from turtle import * 2 3 def moveto(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.实验任务2
task2_1.py
1 from turtle import * 2 3 def moveto(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 def main(): 9 setup(800,600) 10 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.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 main(): 13 setup(800,600) 14 15 radius = 180 16 offset = 20 17 18 for i in range(8): 19 moveto(0,-radius) 20 color(gen_color()) 21 22 begin_fill() 23 circle(radius) 24 end_fill() 25 26 radius -= offset 27 28 hideturtle() 29 done() 30 31 main()
3.实验任务3
task3_1.py
1 from turtle import * 2 3 def square(size = 50,rgb = 'pink'): 4 pencolor(rgb) 5 for i in range(4): 6 fd(size) 7 left(90) 8 9 def main(): 10 setup(800,600) 11 speed(0) 12 13 n = 10 14 for i in range(n): 15 square(80,'orange') 16 left(360/n) 17 18 hideturtle() 19 done() 20 21 main()
task3_2.py
1 from turtle import * 2 3 setup(800,600) 4 pencolor('pink') 5 6 n = 10 7 for i in range(10): 8 for j in range(2): 9 circle(80,90) 10 left(90) 11 12 right(360/n) 13 14 hideturtle() 15 done()
4.实验任务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 20 hideturtle() 21 done()
5.实验任务5
task5_1.py
1 from turtle import * 2 3 def move(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 move(-100,-100) 9 fillcolor('black') 10 begin_fill() 11 for i in range(4): 12 fd(200) 13 left(90) 14 end_fill() 15 16 move(0,-100) 17 left(45) 18 fillcolor('red') 19 begin_fill() 20 for i in range(4): 21 fd(100*2**0.5) 22 left(90) 23 end_fill() 24 25 hideturtle() 26 done()
task5_2.py
1 from turtle import * 2 3 def move(x,y): 4 penup() 5 goto(x,y) 6 pendown() 7 8 move(0,0) 9 pensize(2) 10 pencolor('blue') 11 radius = 40 12 for i in range(5): 13 fd(radius) 14 left(90) 15 circle(radius,90) 16 left(90) 17 fd(radius) 18 left(90) 19 radius+=20 20 hideturtle() 21 done()
task6.py
1 from turtle import * 2 from random import random 3 4 def gen_color(): 5 return tuple((random()for i in range(3))) 6 7 def rect(x,y,color): 8 fillcolor(color) 9 begin_fill() 10 for i in range(2): 11 fd(x) 12 left(90) 13 fd(y) 14 left(90) 15 end_fill() 16 17 setup(800,600) 18 penup() 19 goto(-200,-30) 20 for i in range(20): 21 rect(20,60,gen_color()) 22 fd(20) 23 24 hideturtle() 25 done()
标签:10,20,range,radius,import,实验,def From: https://www.cnblogs.com/wang2003chengxu/p/17473804.html