task1_1.py
实验源码:
from turtle import * def move(x, y): penup() goto(x, y) pendown() def draw(n, size = 100): for i in range(n): fd(size) left(360/n) def main(): pensize(2) pencolor('red') move(-200, 0) draw(3) move(0, 0) draw(4) move(200, 0) draw(5) hideturtle() done() main()
运行结果:
task1_2.py
实验源码:
from turtle import * def moveto(x, y): penup() goto(x, y) pendown() def main(): pensize(2) pencolor('blue') moveto(-150, 0) circle(50) moveto(0, 0) circle(50, steps = 4) moveto(150, 0) circle(50, steps = 5) moveto(300, 0) circle(50, steps = 6) hideturtle() done() main()
运行结果:
task2_1.py
实验源码:
'''以(0,0)为圆心,绘制9个同心圆''' from turtle import * def moveto(x, y): '''把画笔移至坐标(x,y)处''' penup() goto(x, y) pendown() def main(): setup(800, 600) radius = 20 # 圆初始半径 offset = 20 # 同心圆每次位移量 for i in range(9): moveto(0, -radius) circle(radius) radius += offset hideturtle() done() main()
运行结果:
task2_2.py
实验源码:
1 '''以(0, 0)为圆心,绘制9个彩色同心圆,色彩随机生成''' 2 from turtle import * 3 from random import random 4 def moveto(x, y): 5 '''把画笔移至坐标(x,y)处''' 6 penup() 7 goto(x, y) 8 pendown() 9 def gen_color(): 10 '''生成一个以rgb三元组表示的颜色值并返回''' 11 return tuple((random() for i in range(3))) 12 def main(): 13 setup(800, 600) 14 radius = 180 # 圆初始半径 15 offset = 20 # 同心圆每次位移量 16 for i in range(8): 17 moveto(0, -radius) 18 color(gen_color()) 19 20 begin_fill() 21 circle(radius) 22 end_fill() 23 24 radius -= offset 25 hideturtle() 26 done() 27 28 main()
运行结果:
task3_1.py
实验源码:
1 from turtle import * 2 setup(800, 600) 3 pencolor('pink') 4 n = 10 5 for i in range(4): 6 7 for j in range(2): 8 circle(80, 90) 9 left(90) 10 right(360/n) 11 hideturtle() 12 done()
运行结果:
task3_2.py
实验源码:
1 from turtle import * 2 setup(800, 600) 3 pencolor('pink') 4 n = 10 5 for i in range(n): 6 7 for j in range(2): 8 circle(80, 90) 9 left(90) 10 right(360/n) 11 hideturtle() 12 done()
运行结果:
task4.py
实验源码:
1 from turtle import * 2 setup(800, 600) 3 bgcolor('black') 4 pencolor('white') 5 speed(0) 6 angle = 0 7 size = 2 8 n = 5 # 螺旋n边形 9 count = 50 # 循环次数 10 for i in range(count): 11 fd(size) 12 angle += 360/n 13 seth(angle) 14 size += 5 15 hideturtle() 16 done()
运行结果:
task5_1.py
实验源码:
1 from turtle import * 2 setup(800, 600) 3 penup() 4 goto(0,0) 5 pendown() 6 pensize(3) 7 pencolor("black") 8 fillcolor("black") 9 begin_fill() 10 for i in range(4): 11 forward(200) 12 left(90) 13 end_fill() 14 penup() 15 goto(100,0) 16 pendown() 17 pencolor("red") 18 fillcolor("red") 19 begin_fill() 20 left(45) 21 forward(141) 22 left(90) 23 forward(141) 24 left(90) 25 forward(141) 26 left(90) 27 forward(141) 28 end_fill() 29 hideturtle() 30 done()
运行截图:
task5_2.py
实验源码:
1 from turtle import * 2 setup(800, 600) 3 penup() 4 goto(0,0) 5 pendown() 6 pensize(2) 7 pencolor("blue") 8 for i in range(0,5): 9 forward(40+i*20) 10 left(90) 11 circle(40+i*20,90) 12 left(90) 13 forward(40+i*20) 14 left(90) 15 hideturtle() 16 done()
运行结果:
task6.py
实验源码:
1 from turtle import * 2 setup(800,600) 3 pencolor('yellow') 4 color('yellow') 5 begin_fill() 6 pendown() 7 goto(0,0) 8 left(45) 9 forward(200) 10 left(90) 11 circle(200,270) 12 left(90) 13 forward(200) 14 end_fill() 15 bgcolor('black') 16 17 goto(0,100) 18 color('black') 19 begin_fill() 20 circle(20) 21 end_fill() 22 penup() 23 goto(-15,100) 24 pendown() 25 color('white') 26 begin_fill() 27 circle(5) 28 end_fill() 29 pendown() 30 hideturtle() 31 done()
运行结果:
标签:range,实验,import,90,circle,left,fill From: https://www.cnblogs.com/lsh111111/p/17458634.html