task1
1 from turtle import * 2 def move(x, y): 3 4 penup() 5 goto(x, y) 6 pendown() 7 def draw(n, size = 100): 8 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()
from turtle import * def moveto(x, y): '''把画笔移动至坐标(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 '''以(0,0)为圆心,绘制9个同心圆''' 2 from turtle import * 3 def moveto(x, y): 4 penup() 5 goto(x, y) 6 pendown() 7 def main(): 8 setup(800, 600) 9 radius = 20 # 圆初始半径 10 offset = 20 # 同心圆每次位移量 11 for i in range(9): 12 moveto(0, -radius) 13 circle(radius) 14 radius += offset 15 hideturtle() 16 done() 17 main()
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 begin_fill() 20 circle(radius) 21 end_fill() 22 radius -= offset 23 hideturtle() 24 done() 25 main()
task3
1 from turtle import * 2 def square(size = 50, rgb = 'pink'): 3 '''绘制正方形 4 :para: size:int 指定边长 (如未指定参数,使用默认值) 5 :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值) 6 ''' 7 pencolor(rgb) 8 for i in range(4): 9 fd(size) 10 left(90) 11 def main(): 12 setup(800, 600) 13 speed(0) 14 n = 3 15 for i in range(n): 16 square(80) 17 left(360/n) 18 hideturtle() 19 done() 20 main()
1 from turtle import * 2 setup(800, 600) 3 pencolor('pink') 4 n = 4 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()
task4
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 = 4 # 螺旋n边形 9 count = 50 # 循环次数 10 for i in range(count): 11 fd(size) 12 angle += 360/n + 1 13 seth(angle) 14 size += 5 15 hideturtle() 16 done()
task5
from turtle import * def move(x,y): penup() goto(x,y) pendown() def draw(): for i in range(4): fd(200) left(90) def main(): move(-100,-100) color('black') begin_fill() draw() end_fill() move(0,-100) color('red') begin_fill() circle(100,steps = 4) end_fill() hideturtle() done() main()
from turtle import* def move(x,y): '''画笔移动到坐标(x,y)处''' penup() goto(x,y) pendown() pensize(2) pencolor('Blue') n = 5 left(-90) for i in range(n): left(90) move(0,0) fd(40+20*i) left(90) circle(40+20*i,90) left(90) fd(40+20*i) hideturtle() done()
from turtle import * from random import random def move(x,y): penup() goto(x,y) pendown() def gen_color(): return tuple(random() for i in range(3)) def rect(a,b,c): color(c) fd(a) left(90) fd(b) left(90) fd(a) left(90) fd(b) setup(800,600) move(-100,0) for i in range(20): c = gen_color() begin_fill() rect(10,30,c) end_fill() left(90) fd(10) hideturtle() done()
标签:range,实验,import,90,main,def,left From: https://www.cnblogs.com/dughy/p/17458304.html