Python Turtle Graphics
Open This Document
Link to this page: bit.ly/pyturt
Resources
Welcome and Introduction
Your Teacher
I am Dave Briccetti (bri-’cheddy). I am a professional computer programmer who enjoys teaching programming to kids. I teach at three private schools, at the Lafayette Library occasionally, and I have individuals and small groups come to my house in Lafayette for lessons. (More)
Following Links
When you follow links from this document, holding Shift and Cmd while you click will open the page in a new tab and switch to that tab.
Computer Programming
Computer programs are instructions for getting a computer to perform a task, such as these:
- Send a text message
- Play a game
- Manage a calendar
- Drive a car
- Fly a spacecraft
Types of Computers
Programs run on computers of different sizes and types:
- mainframes
- desktops
- laptops
- tablets
- smartphones
- Arduino and Raspberry Pi
Languages
Programs are written using programming languages. Some popular ones are:
- Java
- JavaScript
- C++
- Python
- Scala
About This Course
Python
Python is a popular programming language, used by many, including Google and NASA.
Class Format
Our classes consist of:
- Instruction (Lectures)
- Exercises, where you practice what you’ve just learned, with specific goals
- Creative project work, where you apply what you’ve learned in your own way
- Show and tell, where we share our interesting creations
I usually keep lectures to just a few minutes. During this time I need your focus and full attention. During exercises and creative work, I encourage you to interact with your classmates. Get up, walk around and see what others are doing. Sit where you want, rearranging any time. Just make sure RoomHelper 3000 (see below) knows where you are.
Parents
Many of your parents are likely excited about you learning programming at school. They will be curious about what we are doing. Please point them to this page, so they can follow along with us. Show them at home what you are learning in class. Explaining your programs to others can increase your understanding.
When You Finish
When you complete assigned work, there’s always more to do. You can
- Help others
- Read the reference and learn about more features
- Experiment, and make your own original creations
Let’s Get Started
Here’s a program to start with.
Run it. What things can you change?
Turns
rt(), lt()
Making a Square, the Long Way
from turtle import *
fd(50)
rt(90)
fd(50)
rt(90)
fd(50)
rt(90)
fd(50)
rt(90)
Python Functions
Loops and nested loops
You can repeat code by making a loop:
for n in range(10):
loops 10 times, taking
n
from 0 to 9
for x in range(-200, 201, 100):
loops 5 times,
taking x
from -200 to 200 in steps of 100
Making a Square a Better Way, Using a Loop
from turtle import *
for n in range(4):
fd(50)
rt(360 / 4)
Examples
Grid of Circles
This program makes a grid of circles
Blades
Interactive Graphics with Keyboard Input
Let’s start with this sample.
Randomness
You can use random numbers to affect your turtle graphics. Here’s a starting point.
Challenge: Make more things random
Make these things random:
- pen size
- line length
Bonus:
- Make the color random