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 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() #绘图结束后使窗口停留
Rendering
The above is the detailed content of python draws square spiral. For more information, please follow other related articles on the PHP Chinese website!