turtle绘图的例子
1 #叠加等边三角形 2 import turtle 3 turtle.setup(600,500,200,200) 4 turtle.pensize(1) 5 for i in range(3): 6 turtle.fd(80) 7 turtle.left(120) 8 turtle.fd(40) 9 turtle.left(120) 10 turtle.fd(40) 11 for i in range (3): 12 turtle.right(120) 13 turtle.fd(40)
1 #叠加等边三角形 2 import turtle 3 turtle.setup(600,500,200,200) 4 turtle.pensize(1) 5 for i in range(3): 6 turtle.fd(200) 7 turtle.left(120) 8 turtle.fd(100) 9 turtle.left(120) 10 turtle.fd(100) 11 for i in range (3): 12 turtle.right(120) 13 turtle.fd(100) 14 turtle.hideturtle() 15 turtle.done()
1 #Python蟒蛇绘制 2 import turtle 3 turtle.setup(650, 350, 200, 200) 4 turtle.penup() 5 turtle.fd(-250) 6 turtle.pendown() 7 turtle.pensize(25) 8 turtle.pencolor("purple") 9 turtle.seth(-40) 10 for i in range(4): 11 turtle.circle(40, 80) 12 turtle.circle(-40, 80) 13 turtle.circle(40, 80/2) 14 turtle.fd(40) 15 turtle.circle(16, 180) 16 turtle.fd(40 * 2/3) 17 turtle.done()
1 #六边形 2 import turtle as t 3 t.pensize(2) 4 for i in range(6): 5 t.fd(150) 6 t.left(60)
1 #turtle叠边形绘制 2 import turtle as t 3 t.pensize(2) 4 for i in range(9): 5 t.fd(150) 6 t.left(80)
#风轮 import turtle as t t.pensize(2) for i in range(4): t.seth(90*i) t.fd(150) t.right(90) t.circle(-150, 45) t.goto(0,0)
#奥运五环 import turtle turtle.setup(800,600,200,200) turtle.pensize(4) coordA=(-110,0,110,-55,55) #五个图起点坐标的x值 coordB=(-25,-25,-25,-75,-75) color=["red","blue","green","yellow","black"] for i in range(5): turtle.penup() turtle.goto(coordA[i],coordB[i]) turtle.pencolor(color[i]) turtle.pendown() turtle.circle(50) turtle.hideturtle() turtle.done()
1 #太极图 2 import turtle 3 turtle.speed(0) 4 turtle.fillcolor('black') 5 turtle.begin_fill() 6 turtle.circle(120,180) 7 turtle.left(180) 8 turtle.circle(-60,180) 9 turtle.circle(60,180) 10 turtle.end_fill() 11 turtle.left(180) 12 turtle.circle(-120,180) 13 turtle.right(90) 14 turtle.penup() 15 turtle.fd(70) 16 turtle.left(90) 17 turtle.pendown() 18 turtle.fillcolor('black') 19 turtle.begin_fill() 20 turtle.circle(15) 21 turtle.end_fill() 22 turtle.right(90) 23 turtle.penup() 24 turtle.fd(130) 25 turtle.left(90) 26 turtle.pendown() 27 turtle.fillcolor('white') 28 turtle.begin_fill() 29 turtle.circle(15) 30 turtle.end_fill() 31 turtle.hideturtle() 32 turtle.done()
1 #国际象棋棋盘 2 import turtle 3 turtle.speed(0) 4 width = eval(input()) 5 6 #画黑格 7 def drawSquare(width): 8 turtle.pendown() 9 turtle.begin_fill() 10 turtle.fillcolor("black") 11 for i in range(4): 12 turtle.forward(width) 13 turtle.left(90) 14 turtle.end_fill() 15 turtle.penup() 16 17 for i in range(8): 18 if i % 2 == 0:#偶数行 19 turtle.penup() 20 turtle.goto(0, i * width) 21 turtle.pendown() 22 for j in range(4): 23 drawSquare(width) 24 turtle.fd(2 * width) 25 else: 26 turtle.penup() 27 turtle.goto(width, i * width) 28 turtle.pendown() 29 for j in range(4): 30 drawSquare(width) 31 turtle.fd(2 * width) 32 turtle.penup() 33 turtle.goto(0,0) 34 turtle.pendown() 35 for i in range(4): 36 turtle.forward(8 * width) 37 turtle.left(90) 38 turtle.hideturtle() 39 turtle.done()
1 #八边形绘制 2 import turtle as t 3 t.pensize(2) 4 for i in range(8): 5 t.fd(100) 6 t.left(45)
1 #八角图 2 import turtle as t 3 t.pensize(2) 4 for i in range(8): 5 t.fd(150) 6 t.left(135)