How to draw a spiral in python

(*-*)浩
Release: 2019-07-05 09:04:52
Original
10019 people have browsed it

The following will bring you an article on how to use Turtle to draw spirals.

How to draw a spiral in python

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:

How to draw a spiral in python

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()
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template