我写了一个程序来画一个分形,然后画一个螺旋。螺旋应该遵循fibo模式,本质上应该是递归的
这是密码-
from turtle import Turtle, Screen
import math
t = Turtle()
s = Screen()
t.speed(0)
def square(x, y, side):
t.setpos(x,y)
for i in range(4):
t.forward(side)
t.right(90)
def tiltsquare(x, y, side):
t.left(45)
square(x, y, side)
def squareinsquare(x, y, side):
square(x, y, side)
half = side / 2
b = math.sqrt(half**2 + half**2)
tiltsquare(x, y - side/2, b)
#x,y are start coordinates, stLength is the length of first move and k is the number of moves
spiral(225, -120, 35, 5)
s.exitonclick()
您似乎缺少
a
和b
的初始化:下面是使用此修复程序的代码的简化版本:
相关问题 更多 >
编程相关推荐