Drawing using the Python Turtle
Drawing squirals using the python turtle
The Python Turtle can be used to draw a number of interesting shapes. The general method is to:
- Create a turtle
- Set its line colour, width, drawing speed, the length of the first line to be drawn to a value, such as 2 pixels, and the angle the turtle is to turn through after each line segment is drawn (e.g. 90 degrees)
- Set its pen to the pen up position
- Go to the point where the drawing is to start
- Put the pen down
- Draw a line of a set length from the starting point towards the right
- Turn the turtle through the previously set angle
- Add a few pixels to the length of the next line to be drawn
- Repeat the line drawing, turning and line lengthening as many times as is wanted
If the turning angle is 90 degrees then the shape drawn will be a squiral. Here is some code that will do that.
To draw more interesting shapes use an angle other than 90 degrees. The program used in this repl does that by choosing a random angle. The line colour and number of lines drawn are also randomised.