Python's "turtle" module supports triangular spirals wherein triangles wind around each other at increasing lengths, thus producing a spiral. Drawing such a shape entails delving into a more advanced programming function known as a "for" loop. This allows you to make the computer repeat certain code a number of times, thus removing the need for you to manually type that code over and over again.
Video of the Day
Import the "turtle" module:
The turtle appears at the x=0 and y=0 coordinate of the turtle grid.
Change the turtle's starting position by using the "setpos" function:
Replace "x" with the desired "x" coordinate and "y" with the desired "y" coordinate.
Declare two variables -- one for the distance the turtle should move each loop, and one for the first loop's starting angle:
distance = 120 angle = 10
Create a "for" loop that established a variable "i" in a range of "x." The latter value refers to the number of loops the turtle will make:
for i in range(x):
Replace "x" with a large number to achieve a big spiral or a small number to achieve a smaller spiral.
Insert "turtle.forward" and "turtle.left" movement codes into the loop to make the turtle move. Use the variables you previously declared:
Add a step immediately after the movement code that increases the movement angle during each loop. This is necessary to mimic the shape of a spiral:
angle = angle + 5