The following will bring you an article on how to use Turtle to draw spirals.
The simplest square spiral curve graph, see the example: (Recommended learning: Python video tutorial)
Set the starting point of the brush position in advance to (-450, 150), adjust the brush color to blue, and then use a for loop to shorten the distance drawn by the brush. The n value of turtle.fd(n) in the for loop loops Subtract one at a time, and then you have the most basic square spiral curve graph
The result graph is as follows:
Code:
import turtle n = 500 turtle.penup() turtle.goto(-450,150) turtle.pendown() turtle.pencolor("blue") for i in range(500): n = n - 1 #n -= 1 turtle.speed(100) turtle.fd(n) turtle.right(90) turtle.pendone()
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to draw a spiral in python. For more information, please follow other related articles on the PHP Chinese website!