import turtle
turtle.shape ('turtle')
d = 20 #Distance
a = 1 #StartingAngle
x = 200 #Num of loops
for i in range (x):
turtle.left(a)
turtle.forward(d)
a = a + 5
import turtle
from math import sin,cos,pi
t=turtle.Turtle()
t.speed(0)
n=50 #number of spirals
d=10 #distance between 2 spirals
r=0 #radius
x,y = 0, 0
cur_r = r
for i in range(n):
for a in range(1,360, 4):
r = cur_r + d*a/360.0
a *= pi/180.0
y = r*sin(a)
x = r*cos(a)
turtle.goto(x,y)
cur_r += d
如果您使用的程序不是IDLE(例如pycharm),请添加
^{pr2}$在代码末尾
您在循环中增加了错误的变量。在
螺旋线就像一个“半径随时间而增大的圆”。在
您应该随时间增加
d
变量,而不是增加角度a
。每个循环的增加量对于确定螺旋线的外观是至关重要的,但是通过一些计算或反复尝试,您可以获得一个很好的增加值。在相关问题 更多 >
编程相关推荐