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

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

Tiugo image

Fast, Lean, and Fully Extensible

CKEditor 5 is built for developers who value flexibility and speed. Pick the features that matter, drop the ones that don’t and enjoy a high-performance WYSIWYG that fits into your workflow

Start now

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay