OpenBrackets
Intermediate Python
Week 3 Day 1
Welcome!
Welcome to class!
This is the Intermediate Python Programming class. Make sure you’re in the right place!
Schedule for today:
Reminders
Aidan and Stanley are both out for the first 30 minutes of class, so Nan will be subbing in.
Please keep your camera on as much as possible! This helps us know how you’re doing and whether you’re following along. It will also help you stay more engaged.
Don’t be afraid to ask questions!
Asking Questions
Type in chat
Or
How are you doing?
1 2 3 4 5 6 7 8 9 10
Intro to Turtle : Part 2
Drawing
Drawing with Turtle
.goto(x, y) moves the Turtle to a new position (x, y) while drawing
The turtle starts at (0, 0)
Try drawing a square with your turtle! You’ll need to use .goto 4 times.
Exercise
Challenge: Pick some letters of the alphabet and draw them!
(-110, -20)
(-80, 100)
(0, 0)
(100, 100)
(100, 0)
(0, 100)
Changing Turtle Pen Color
Changing the turtle’s color will also change the color of the lines it draws. We learned how to change the turtle’s color last class.
We don’t have to change the color of the turtle right after we make it. You can draw something, change the color, and then draw something else.
my_turtle.color(new_color)
Exercise
Make each side of your square a different color!
Challenge: Pick some letters of the alphabet and draw them! If you’ve already done this, make each letter a different random color.
(-110, -20)
(-80, 100)
(0, 0)
(100, 100)
(100, 0)
(0, 100)
Pen Up/Down
In order to draw multiple separate shapes, we need to move the pen without drawing.
Exercise
5 minute break!
Writing text with Turtle
.write("text", False, "center", ("", 20, "normal"))
This is the text that we want to write.
Don’t worry about this for now. (If you’re curious, this parameter determines whether the turtle should move or not.)
This is the alignment for our text. “center” align means that our text will be centered around the turtle’s current position.
This controls what font name the text will be in. For now, we’ll leave this blank for default. (Using different fonts can cause system portability issues.)
This is the font size.
This is the font style. We can have “normal”, “bold”, “italic”, and “underline”.
Exercise
Write your name in the center of the screen.
Another method for moving
.forward(distance) will move the turtle forward by whatever distance you want
.setheading(degrees) changes the direction the turtle is facing
0°
90°
270°
180°
Getting the coordinate values
Move a turtle from the origin to the right by 10 pixels using a loop. When its x position becomes greater than or equal to 200, stop the turtle.
Moving Turtles at the Same Time
Add a second turtle which starts below the first turtle and moves to the right until its x position is greater than 200.
Mini Project: Randomized Drawings
We can make random drawings with three different methods
For all of these, we’ll use a for loop to keep moving the turtle around. Then, depending on which method we’re using, we’ll write code to tell the turtle how to move.
Thanks for coming to class!
Please let us know if you have any questions!