python draws square spiral

angryTom
Release: 2020-02-13 10:50:39
Original
27428 people have browsed it

This article introduces how to draw a square spiral in python using the turtle library. The code is very simple. I hope it will be helpful to students who are learning python!

python draws square spiral

Python draws a square spiral

Use python to draw a spiral, using the turtle library, which is python2. A simple drawing tool introduced in version 6 is called Turtle Graphics. The turtle library is an internal library of Python and can be imported when used.

import turtle as t
t.pen(speed=0)   #加快绘图速度
t.penup()
t.goto(-200, -200)     #以左下角某处为起点
t.pendown()
t.seth(0)
length = 400
while (length !=0):    #利用正方形螺旋线的性质来绘图
    t.fd(length)
    t.left(90)
    length -= 2.5
t.hideturtle()         #绘图结束后把海龟头(笔触头)隐藏起来
t.done()               #绘图结束后使窗口停留
Copy after login

Rendering

python draws square spiral

The above is the detailed content of python draws square spiral. 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