# Harriss Spiral Py5

**URL:** <https://discourse.processing.org/t/harriss-spiral-py5/45286>\
**Category:** py5\
**Created:** [November 6, 2024, 10:52pm UTC](https://discourse.processing.org/t/harriss-spiral-py5/45286 "2024-11-06T22:52:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 6, 2024, 10:52pm UTC](https://discourse.processing.org/t/harriss-spiral-py5/45286/1 "2024-11-06T22:52:34Z")

</div>

The following demo is a port of Harriss Spiral from Processing to Py5; a **Thonny editor is required**. Uses modified Turtle Graphics with recursion.

```auto
# 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:**

 ![hsp_py5](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/e/7e037d8bb1d422f89c8d2a1d12d22b11b8ad31b3.png)

**MultiSpiral Design:**

```auto
# Reference for Turtle Graphics in Processing
# https://gist.githubusercontent.com/nataliefreed/8483050/raw/9e3f1d0f44bcb0c872762e4b984358d375e7b5fa/turtle.pde

end = 0.0
loc = 0.0
newLoc = 0.0
h = 600.0
w = (h/1.325)/1.325
orientation = radians(90)
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(800, 750)
    surface = get_surface()
    surface.set_title("Harriss Spiral Design")
    showLines = False
    loc = Py5Vector(width/2 + 100,height/2 + 200)
    no_loop()
    
def draw():
    global orientation
    global rotation
    global h
    global w

# Base Spiral
    harriss(7)
# Right Upper Spiral
    jumpTo(495, 230)
    h = 300.0
    w = (h/1.325)/1.325
    orientation = radians(0)
    rotation = 45
    harriss(8)
# Left Upper Spiral
    jumpTo(240, 238)
    h = 250
    w = (h/1.325)/1.325
    rotation = -45
    orientation = radians(90)
    harriss(7)
# Left Lower Spiral
    jumpTo(240, 425)
    h = 200
    w = (h/1.325)/1.325
    rotation = 225
    orientation = radians(180)
    harriss(6);
# Center Lower Spiral
    jumpTo(390, 425)
    h = 175
    w = (h/1.325)/1.325
    rotation = 135
    orientation = radians(-90)
    harriss(5)    
    
# ======= Turtle Graphics Functions =========
    
def fd(w,iteration):
    global loc
    global newLoc
    global end
    global rotation
    
    polar(w,orientation)
    end = loc + newLoc

    if(showLines):
        stroke(0)
        stroke_weight(1)
        line(loc.x,loc.y,end.x,end.y)
    
    no_fill()
    stroke(random(255),0,random(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

def jumpTo(x,y):
    global loc
    loc = Py5Vector(x,y)
    
def polar(r,theta):
    global newLoc
    newLoc = Py5Vector(r*cos(theta),r*sin(-theta))

```

**Output:**

 ![py](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/a/8a336e4c127c63d6a7e8e707d80927a5f99a1561.png)

---

<div class="post-metadata">

**Author:** ![hx2A](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hx2a/32/14322_2.png) [@hx2A](https://discourse.processing.org/u/hx2A)\
**Post date:** [November 10, 2024, 9:25pm UTC](https://discourse.processing.org/t/harriss-spiral-py5/45286/2 "2024-11-10T21:25:03Z")

</div>

Nice work, @svan ! Thank you for sharing this. The `draw()` function uses a reduced set of functions that would be great for beginner programmers to learn programming. Turtle Graphics programming is how I started with coding.

Also, you inadvertently uncovered a bug in py5…will open an issue on github.
