Welcome to the Twentieth of Altitude Foundation’s #MicroChallenges2020
Today’s challenge will help you create turtle-y awesome images!
What’s a Micro Challenge?
These challenges are short activities to help you develop, revise or refresh your coding skills, posted every Monday, Wednesday and Friday.
Micro Challenge #20
Turtle is an art feature in Python – a ‘turtle’ which leaves a trail of coloured pixels after it. It is in effect a pre-installed library, which means it has a series of attributes stored in it. You can learn more here.
Turtle uses a basic Python format language – for example, if you wanted to move forward 100 pixels, the code would be: turtle.forward(100). If you want to turn, you indicate the number of degrees: turtle.right(90).
What might I be coding here:
- import turtle [Note: this imports the turtle library into your coding software]
- turtle.forward(100)
- turtle.right(90)
- turtle.forward(100)
- turtle.right(90)
- turtle.forward(100)
- turtle.right(90)
- turtle.forward(100)
If you guessed square – congratulations!
A faster way of coding this might be using loops. Which would look like this:
Import turtle
for i in range 4 [Note: this piece of code tells the turtle to repeat the action 4 times]
turtle.forward(100)
turtle.right(90)
If you want to create multiple images with spaces between them, turtle.penup() stops the turtle from ‘drawing’; turtle.pendown() makes it start again.
The Challenge:
Code an image using the turtle. It can be as simple or complicated as you like. Where could you simplify the code using repetitions?
How might Turtle make drawing intricate patterns easier?
Review it:
- Have you simplified the code as much as possible? Remember, you need to balance clarity with conciseness – the code needs to be understandable by a computer, but also as short as possible, to minimise the work you have to do to code.
- Try out your code in Trinket! What can you create?
Advanced:
- Functions are a useful way of speeding up coding, particularly if you want to draw something like a spirograph image. You can learn more about that here – and test out your maths skills as well!
Share it
We would love to see what you have created! Please send any pictures, videos, or files of your activities to us – either via Facebook, Twitter or Instagram using #MicroChallenges2020 or to challenges@altitudefoundation.org. If you are emailing them to us, please let us know if you are happy for us to share your stuff on our social media platforms (with credit, of course).
Sign-up here to receive a weekly email with Micro Challenges top tips and solutions: