turtle is a pre-installed Python library that enables users to create pictures and shapes by providing them with a virtual canvas. The onscreen pen that you use for drawing is called the turtle and this is what gives the library its name.
import turtle
pen = turtle.Turtle()
def ring(col, rad):
pen.fillcolor(col)
pen.begin_fill()
pen.circle(rad)
pen.end_fill()
pen.up()
pen.setpos(-35, 95)
pen.down()
ring('black', 15)
# Draw second ear
pen.up()
pen.setpos(35, 95)
pen.down()
ring('black', 15)
pen.up()
pen.setpos(0, 35)
pen.down()
ring('white', 40)
# Draw first eye
pen.up()
pen.setpos(-18, 75)
pen.down()
ring('black', 8)
pen.up()
pen.setpos(18, 75)
pen.down()
ring('black', 8)
pen.up()
pen.setpos(-18, 77)
pen.down()
ring('white', 4)
pen.up()
pen.setpos(18, 77)
pen.down()
ring('white', 4)
pen.up()
pen.setpos(0, 55)
pen.down()
ring('black', 5)
pen.up()
pen.setpos(0, 55)
pen.down()
pen.right(90)
pen.circle(5, 180)
pen.up()
pen.setpos(0, 55)
pen.down()
pen.left(360)
pen.circle(5, -180)
pen.hideturtle()
turtle.done()
1 Comment
[…] is a pre-installed Python library that enables users to create pictures and shapes by providing them with a virtual canvas. The onscreen pen that you use for drawing is called the […]