Materials:
Computer or Raspberry Pi
Python IDE
If you are working on a raspberry pi, you can find “Thonny IDE” under the programming tab. Please open this.
If you are not working on a raspberry pi and need to install an IDE:
Please visit https://www.python.org/downloads/
Download the latest version of Python for your correct system (Windows, Mac, etc.)
Once the downloading process is complete, search your computer for an application named “IDLE” and open it. This is your Python IDE. (The logo for IDLE is the same as the one on the right)
Now that you have either located or downloaded a Python IDE, open it, if you haven’t already.
Locate the command prompt. It will likely be the first thing to pop up and have arrows like this >>>>>>On raspberry Pi’s IDE, sometimes the command prompt is towards the bottom of the Python screen.
In the command prompt, type the following commands(press enter after each command):
import turtle
tom = turtle.Turtle
Note that "tom" is just the name I have chosen to give my variable. You may name it whatever you like.
Type a variety of basic turtle commands in the Python shell to see what they do! Here are some examples to get you started:
tom.forward(100)
tom.circle(80)
tom.backward(45)
tom.right(90)
tom.penup()
tom.pendown()
tom.reset
()Note that this is a VERY basic summary of my much more developed turtle worksheet I made. In that worksheet you will find step by step instructions on how to draw a variety of shapes in turtle and a summary of more complex commands.
You can run turtle from both the Python shell and a file itself. It’s up to you. If you want to save your code and work, it would be best to use a file. If you are just testing what different turtle commands do, using the shell is just fine. The code to start turtle is the same regardless. Since we will initially just be testing our code, let’s use the shell.
In the shell prompt, type “import turtle”
Create a variable and set it equal to turtle.Turtle() This should cause a popup window to appear. We will name our variable “tom”. You are welcome to use a different name, but if you do, make sure to remember it as it will be very important for the rest of our activities. The end result should be tom = turtle.Turtle()
Now we will draw our first shape, a circle! Type this command: tom.circle(50)
If you named your variable something other than “tom”, you would place that name in front of the dot.
This should have appeared on your Canvas after typing that command. You drew a circle!
The number inside the parenthesis specified to the program how big the radius of the circle should be. Try runningthe same command but with different numbers to see what sorts of circles you’ll draw!
Once you have finished drawing circles, please type this command: tom.reset()
This will reset our virtual canvas to make space for the next shape we will create!
There are two commands involved in drawing a square:
tom.forward() –draws aside of the square
tom.right() –turns our pen to face the correct direction for drawing the next side of the square.
We need to execute these two commands 4 times to draw our square. This is the perfect time to use a for loop!
Your turtle variable should already be initialized. If it isn’t, refer to the “Starting Turtle” section.
Create a for loop like the one below and run it.
Look! We made a square.
Try experimenting with the same for loop, but change the number in tom.forward(), tom.right(), or both! Do you get a different sized shape? A completely different shape?
Remember to run this command when you are done drawing squares to reset your canvas: tom.reset()
Drawing a triangle is like drawing a square, except it only has three sides and we need to turn our pen at a sharper angle. Here are the commands associated with drawing a triangle:
tom.forward()
tom.left()
Your turtle variable should already be initialized. If it isn’t, refer to the “Starting Turtle” section.
Create a for loop like theone below and run it.
Congratulations! You just finished drawing your first triangle!
Now, try running the for loop again, but see what happens when you make some/all of these changes!
Change the number in tom.forward() or tom.left()
Replace tom.left(120) with tom.right(120)
As always, please reset your canvas when you are finished experimenting: tom.reset()
Drawing a rectangle is a little more complex than the other shapes we have drawn today. That is because unlike squares and triangles, rectangles do not have the same length on each side.
Let’s look at the code to draw a rectangle and we will analyze how it works.
Your turtle variable should already be initialized. If it isn’t, refer to the “Starting Turtle” section.
We are going to use this for loop to create our rectangle. The initial setup is the same, but you will notice the “if else” statement inside the for loop.
The first line says we will run the code 4 times.
The if statement says if it is the 1stor 3rd time running the code, draw a longer side of the rectangle and turn the pencil right.
The else statement says if it isn’tthe 1stor 3rd time running the code (meaning it would be the 2ndor 4thtime), draw a shorter side of the rectangle and turn the pencil right.
Now that you understand how this code works a bit better, let’s run it and see if we can draw a rectangle!
Now, using the shapes we have learned, we are going to make a creature.
Here's an example:
Your creature should have:
A head
At least 1 eye
A mouth
A body
At least 2 legs
Tips:
It may be helpful to sketch/visualize what sort of creature you want to draw before you start coding it.
You can use as many or as few colors as you like
It may be helpful to write your code in a file instead of using the shell, that way you can save your progress and make small changes when necessary.
DO NOT name your file “turtle”. This will confuse the computer and cause your program not to work. You may name your file anything other than “turtle”.
Download the PDF below