With vector graphics lines and shapes can be drawn to any scale without losing quality because unlike photographs, the mathematics to draw the image is stored instead of the individual-coloured pixels. Vectors are also great for sending instructions to hardware such as laser cutters and embroidery machines.
Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.
Note, in Trinket, the turtle library is only supported in Python v2, so there is no support for the match/case command.
Watch this video to learn about the new concepts shown in the program:
The new commands used in this program and others that may be useful. Select them below to learn more:
Turns the turtle left x degrees. Turns are always made from the perspective of the turtle, not the programmer, so if the turtle is facing down, left will be right and right will be left!
Turns the turtle right x degrees. Turns are always made from the perspective of the turtle, not the programmer, so if the turtle is facing down, left will be right and right will be left!
Moves the turtle forward x pixels. If the pen is down (default) a line will be drawn from the start position to the end position. If the pen is up a line will not be drawn.
Moves the turtle backwards pixels without turning around. If the pen is down (default) a line will be drawn from the start position to the end position. If the pen is up a line will not be drawn.
Sets the pen to be x pixels wide. The default is 1. Larger numbers result in thicker lines being drawn.
Ends the turtle program. This is not necessary, but some implementations of turtle require this to prevent the graphics canvas window being closed automatically when the program ends. It is good practice to include this command at the end of programs using turtle.
There are shortcuts and alternatives to many of the turtle commands, such as turtle.fd, turtle.bk, turtle.backward.
Questions to think about with this program to check your understanding:
If a turtle is facing downwards, which direction would it be facing after the command turtle.left(90)?
Change the program below so that it:
Run your code to check that your program has met the success criteria and produces the required output.