任务一
1
1 from turtle import * 2 def move(x, y): 3 '''画笔移动到坐标(x,y)处''' 4 penup() 5 goto(x, y) 6 pendown() 7 def draw(n, size = 100): 8 '''绘制边长为size的正n变形''' 9 for i in range(n): 10 fd(size) 11 left(360/n) 12 def main(): 13 pensize(2) 14 pencolor('red') 15 move(-200, 0) 16 draw(3) 17 move(0, 0) 18 draw(4) 19 move(200, 0) 20 draw(5) 21 hideturtle() 22 done() 23 main()
2
1 from turtle import * 2 def moveto(x, y): 3 '''把画笔移动至坐标(x, y)处''' 4 penup() 5 goto(x, y) 6 pendown() 7 def main():
8 pensize(2) 9 pencolor('blue') 10 moveto(-150, 0) 11 circle(50) 12 moveto(0, 0) 13 circle(50, steps = 4) 14 moveto(150, 0) 15 circle(50, steps = 5) 16 moveto(300, 0) 17 circle(50, steps = 6) 18 hideturtle() 19 done() 20 main()
任务二
1
1 from turtle import * 2 def moveto(x, y): 3 penup() 4 goto(x, y) 5 pendown() 6 def main(): 7 setup(800, 600) 8 radius = 20 9 offset = 20 10 for i in range(9): 11 moveto(0, -radius) 12 circle(radius) 13 radius += offset 14 hideturtle() 15 done() 16 main()
2
1 from turtle import * 2 from random import random 3 def moveto(x, y): 4 penup() 5 goto(x, y) 6 pendown() 7 def gen_color(): 8 return tuple((random() for i in range(3))) 9 def main(): 10 speed(0) 11 setup(800, 600) 12 radius = 180 13 offset = 20 14 for i in range(8): 15 moveto(0, -radius) 16 color(gen_color()) 17 begin_fill() 18 circle(radius) 19 end_fill() 20 radius -= offset 21 hideturtle() 22 done() 23 main()
任务三
1
1 from turtle import * 2 def square(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 = 50 11 for i in range(n): 12 square(80) 13 left(360/n) 14 hideturtle() 15 done() 16 main()
2
1 from turtle import * 2 speed(0) 3 setup(800, 600) 4 pencolor('pink') 5 n = 50 6 for i in range(n): 7 # 绘制一片花瓣 8 for j in range(2): 9 circle(80, 90) 10 left(90) 11 right(360/n) 12 hideturtle() 13 done()
任务四
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 9 count = 100 10 for i in range(count): 11 fd(size) 12 angle += 360/n 13 seth(angle) 14 size += 5 15 hideturtle() 16 done()
任务五
1
1 from turtle import * 2 goto(-100,-100) 3 color('black') 4 begin_fill() 5 for i in range(4): 6 fd(200) 7 left(90) 8 end_fill() 9 goto(0,-100) 10 color('red') 11 begin_fill() 12 circle(100,steps=4) 13 end_fill() 14hideturtle()
15 done()
2
1 from turtle import * 2 pensize(2) 3 pencolor('blue') 4 for i in range(5): 5 fd(40+20*i) 6 left(90) 7 circle(40+20*i,90) 8 left(90) 9 fd(40+20*i) 10 left(90) 11 hideturtle() 12 done()
任务六
1 from turtle import * 2 bgcolor('black') 3 color('yellow') 4 begin_fill() 5 left(45) 6 forward(100) 7 left(90) 8 circle(100,270) 9 left(90) 10 forward(100) 11 end_fill() 12 color('black') 13 penup() 14 sety(50) 15 pendown() 16 begin_fill() 17 circle(10) 18 end_fill() 19 color('white') 20 penup() 21 sety(50) 22 pendown() 23 begin_fill() 24 circle(3) 25 end_fill() 26 hideturtle() 27 28 done()
标签:10,range,实验,import,circle,def,fill From: https://www.cnblogs.com/new22/p/17466725.html