DEV Community

petercour
petercour

Posted on

1 1

Turtle Shapes with Python

The turtle module lets you draw all kinds of things. It's originally made for kids, but it's fun :)

This program below draw a bunch of shapes on the window including a circle, square and triangle.

Python Turtle shapes

If you run the program you see the turtle drawing the shapes. The turtle starts walking and leaves behind a trail. Over time you see the shapes show up.

#!/usr/bin/python3
import turtle
import random    

def drawshape(sides, length):
    angle = 360.0 / sides
    for sides in range(sides):
        turtle.forward(length)
        turtle.right(angle)

def moveTurtle(x, y):
    turtle.penup()
    turtle.goto(x,y)
    turtle.pendown()

def drawsquare(length):
    drawshape(4,length)

def drawtriangle(length):
    drawshape(3,length)

def drawcircle(length):
    drawshape(360, length)

drawcircle(1)
drawsquare(100)
drawtriangle(250)

turtle.done()

Result:

Learn Python:

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay