The following demo is a port of Harriss Spiral from Processing to Py5; a Thonny editor is required. Uses modified Turtle Graphics with recursion.
# Reference for Turtle Graphics in Processing
# https://gist.githubusercontent.com/nataliefreed/8483050/raw/9e3f1d0f44bcb0c872762e4b984358d375e7b5fa/turtle.pde
orientation = radians(0)
end = 0.0
loc = 0.0
newLoc = 0.0
h = 600.0
w = (h/1.325)/1.325
rotation = 45
showLines = False
def harriss(iteration):
global w
if(iteration > 0):
iteration -= 1
fd(w,iteration)
lt(radians(90))
w = w/1.325
harriss(iteration)
def setup():
global loc
global showLines
size(700, 600)
surface = get_surface()
surface.set_title("Harriss Spiral")
showLines = False
loc = Py5Vector(width/2 - 150,height/2 + 100)
no_loop()
def draw():
harriss(8)
# ======= Turtle Graphics Functions =========
def fd(w,iteration):
global loc
global newLoc
global end
global rotation
polar(w,orientation)
end = loc + newLoc
print("loc = ",loc)
print("newLoc =",newLoc)
print("end = ",end)
print("====================")
if(showLines):
stroke(0)
stroke_weight(1)
line(loc.x,loc.y,end.x,end.y)
no_fill()
stroke(0,0,255)
stroke_weight(12);
if ((iteration == 7) or (iteration == 3)):
arc(loc.x + w/2, loc.y - w/2, w*1.414, w*1.414, radians(rotation), radians(rotation + 90));
if ((iteration == 6) or (iteration == 2)):
arc(loc.x - w/2, loc.y - w/2, w*1.414, w*1.414, radians(rotation), radians(rotation + 90));
if ((iteration == 5) or (iteration == 1)):
arc(loc.x - w/2, loc.y + w/2, w*1.414, w*1.414, radians(rotation), radians(rotation + 90));
if ((iteration == 4) or (iteration == 0)):
arc(loc.x + w/2, loc.y + w/2, w*1.414, w*1.414, radians(rotation), radians(rotation + 90));
loc = end
rotation -= 90
def lt(theta):
global orientation
orientation += theta
println("new orientation =",orientation)
def polar(r,theta):
global newLoc
newLoc = Py5Vector(r*cos(theta),r*sin(-theta))
Output: