意外看到 Python 的turtle
海龟绘图模块,就是这绘制一个在Blender里面会者的费马螺旋,效果还不错,方便快捷。
错误的费马螺旋
效果展示
代码
"""这是一个绘制螺旋图形的代码"""
# Start
from turtle import*
counts = 250
Cond = 1
x = 1
speed(30)
dot(5,"black")
dotdiam = 5
while(Cond < counts ):
startradius = 1
angle = 137.5
radius = startradius * x
if Cond < 100:
dotdiam = dotdiam + 0.2
else:
dotdiam = dotdiam - 0.1
penup()
circle(radius,angle)
pendown()
dot(dotdiam,"black")
Cond = Cond + 1
x = x + 1
正确的画法
规律
如果假设N为点的序号,那么原点就是第0个点,N=0接下来偏移的第1个点为N=1,假设第一个偏移的半径是R
from turtle import*
counts = 250 Cond = 1 dotdiam = 20
speed(30) dot(dotdiam,”black”)
while(Cond < counts ):
startradius = 20
angle = 137.5
radius = (Cond ** 0.5) * startradius
if Cond < 100:
dotdiam = dotdiam
else:
dotdiam = dotdiam
penup()
circle(radius,angle)
pendown()
dot(dotdiam,"black")
Cond = Cond + 1
<a name="pAnsA"></a>
# 其他练习

```python
#### 这是一个绘制回字形方格图形的代码 #####
from turtle import *
l = int (input ("请输入初始方框边长:")) #让用户输入初始方框的边长
couts = int(input("请输入绘制的圈数:")) #让用户输入绘制的圈数,也是程序运行时未画的圈数
ex = int(input("请输入递增间距:")) #让用户输入两个方框之间的间距
speed(10)
color("red")
while (couts != 0): #当剩余圈数不是0时,进入循环绘制
tl = l / 2 #以中心(0,0)作为方框的中心,那么取一半作为方框点的坐标
if couts != 0: #当剩余圈数不是0时,进入ture条件分支
pu() #抬起笔尖
goto(-tl,tl) #移动到第一个点
pd() #落下笔刷,准备绘制
goto(tl,tl) #绘制到第二个点
goto(tl,-tl) #绘制到第三个点
goto(-tl,-tl) #绘制到第四个点
goto(-tl,tl) #绘制到第一个点,闭合方框
couts = couts - 1 #减去1圈,得到剩余圈数
l = l + ex *2 #计算下一圈的边长
continue #循环继续
else :
break #绘制完毕,跳出循环
mainloop() #绘制结束,不自动退出Python Turtle窗口