4. Turtle Drawing Practice¶
Quick Overview of Day
Use for
loops and functions to draw shapes elegantly. Continue working on a Python turtle graphics assignment, focused on repetition and conditionals.
CS20-CP1 Apply various problem-solving strategies to solve programming problems throughout Computer Science 20.
CS20-FP1 Utilize different data types, including integer, floating point, Boolean and string, to solve programming problems.
CS20-FP2 Investigate how control structures affect program flow.
CS20-FP3 Construct and utilize functions to create reusable pieces of code.
4.1. Practice Problems¶
4.1.1. Inner Squares¶
Define a function similar to draw_square(my_turtle, side_length)
and call it twice to draw the shape above. You may find it helpful define a new version of of this function, instead of reusing the one from yesterday. Perhaps you might not start in the same location as we did the last time we drew a square?
For the first three problems, beginning your drawing from the middle of the square, then ending in the middle of the square (facing the same direction as you started) can be a really helpful strategy. You might want to create a function such as draw_square_from_centre(the_turtle, side_length)
that does this. This new function could even call your old draw_square(my_turtle, side_length)
function, if you’d like.
4.1.2. Square Logo¶
Draw the shape above. Depending on how you defined the function in the problem above, you may be able to easily use reuse your function.
4.1.3. Overlapped Squares¶
Draw the shape above. Depending on how you defined your earlier function(s) in the problems aboves, you may be able to easily use reuse your function(s).
4.1.4. Bonus - If You Are Done Before Others¶
Draw the shape above. Think carefully about how you might be able to draw this elegantly (efficiently and readably)! Creating an adapted version of one of your previous functions isn’t a bad idea…
4.2. Turtle Graphics Assignment¶
Use the rest of this class time to keep working on your current Python assignment (possibly a turtle graphics drawing, with a focus on looping and conditionals).