Skip to content

Workshop 1 - Sem 1 2024

In this workshop, we'll be giving you the tools to create a full illustration with Turtle graphics. Below are basic steps that you could follow to draw with Turtle and a cheat sheet of different commands you can use to create the picture you want.

Direction/Movement Commands

One of the most important things in using Turtle is figuring out how it moves. Once you've figured out how it moves you can easily draw anything you want with it.

Command Description
goto(x , y) Goes to the specific coordinates that were given
forward(distance) Moves the turtle forward by a specified distance.
backward(distance) Moves the turtle backward by a specified distance.
setheading(angle) Sets the direction of the turtle to a specific angle. (has an absolute angle regardless of its current orientation)
right(angle) Turns the turtle clockwise by a specified angle. (will depend on its current orientation )
left(angle) Turns the turtle counterclockwise by a specified angle. (will depend on its current orientation )
penup() Lifts the pen off the drawing surface so the turtle can move without drawing.
pendown() Puts the pen back down on the drawing surface so the turtle can draw as it moves.
speed(speed) Sets the speed of the turtle (0 = fastest, 1 = slowest).

Properties Commands

turtle colors

Command Description
color(colorstring) Sets pen color.
pencolor(colorstring) Sets pen color.
fillcolor(colorstring) Sets fill color.
bgcolor(colorstring) Sets background color.
width(width) Sets pen width.
begin_fill() Begins filling area bounded by subsequent drawing commands.
end_fill() Ends filling area started by begin_fill().
clear() Clears drawing canvas.

Steps in Drawing with Turtle

Here are simplified steps for drawing in Turtle: Sure, here's the Markdown code segment with the numbered list formatted as an ordered list:

Step 1: Establish a starting point by setting coordinates.

penup()
goto(-100, 100)  # Example starting position

Step 2: Define drawing properties such as color and the width of the pen.

pendown()  # Put the pen down to start drawing
pensize(2)  # Set the thickness of the lines
color("blue")  # Set the color of the lines

Step 3: Utilize Turtle to create shapes and lines for your image. If you are going to draw something particular, the easiest way to do this is by looking at how to do it in shapes. You can make your own functions that already draw the shapes as well, you can decide the parameters it takes.

from turtle import *

def draw_circle(radius, color):
    color(color)
    begin_fill()
    circle(radius)
    end_fill()

def draw_triangle(side_length, color):
    color(color)
    begin_fill()
    for _ in range(3):
        forward(side_length)
        left(120)
    end_fill()

# Draw the body
draw_circle(150, "black")

# Move up for the head
penup()
forward(50)
pendown()

# Draw the head
draw_circle(100, "black")

# Draw the left ear
penup()
forward(50)
pendown()
draw_triangle(60, "black")

# Draw the right ear
penup()
backward(100)
pendown()
draw_triangle(60, "black")

# Draw the left eye
penup()
forward(40)
left(90)
forward(40)
pendown()
draw_circle(20, "white")

# Draw the right eye
penup()
backward(80)
pendown()
draw_circle(20, "white")

# Draw the left pupil
penup()
forward(10)
left(90)
forward(20)
pendown()
draw_circle(10, "black")

# Draw the right pupil
penup()
backward(40)
pendown()
draw_circle(10, "black")

# Draw the nose
penup()
forward(10)
right(90)
forward(20)
pendown()
draw_circle(15, "pink")

# Draw the mouth
penup()
backward(10)
pendown()
color("black")
right(90)
circle(20, 180)

done()