1.五角星绘制
import turtle turtle.fillcolor("red") turtle.begin_fill() while True: turtle.forward(220) turtle.right(144) if abs(turtle.pos()) < 1: break turtle.fd(84) for i in range(5): turtle.fd(52) turtle.right(72) turtle.end_fill() turtle.done()
2.六角形绘制
import turtle turtle.pencolor("pink") turtle.left(30) turtle.forward(144) turtle.right(60) turtle.forward(144) turtle.right(60) turtle.forward(144) turtle.right(60) turtle.forward(144) turtle.right(60) turtle.forward(144) turtle.right(60) turtle.forward(144) turtle.forward(144) turtle.right(120) turtle.forward(144) turtle.left(60) turtle.forward(144) turtle.right(120) turtle.forward(144) turtle.left(60) turtle.forward(144) turtle.right(120) turtle.forward(144) turtle.left(60) turtle.forward(144) turtle.right(120) turtle.forward(144) turtle.left(60) turtle.forward(144) turtle.right(120) turtle.forward(144) turtle.left(60) turtle.forward(144) turtle.right(120) turtle.forward(144) turtle.exitonclick()
3.叠加等边三角形绘制
import turtle as t t.pencolor("purple") #笔触为紫色 #绘制外部大三角形 t.fd(200) t.seth(120) t.fd(200) t.seth(-120) t.fd(200) #绘制内部小三角形 t.seth(0) t.fd(100) t.seth(60) t.fd(100) t.seth(180) t.fd(100) t.seth(-60) t.fd(100) t.seth(120) t.fd(100) t.seth(0) t.done()