Search code examples
primesnetlogospiral

How does one achieve a square spiral like the the Ulam spiral in Netlogo?


I spent the morning trying to find an easy function (x,y) -> n that would number the patches like this

enter image description here

I was not successful. Do any of Y'all have any experience or suggestions?


Solution

  • Here is my take on it:

    patches-own [ n ]
    
    to setup
      clear-all
      resize-world -4 4 -4 4 ; so it looks better, but use any size you like...
      create-turtles 1 [
        set heading 180
        foreach n-values count patches [ ? + 1 ] [
          set n ?
          if [ n = 0 ] of patch-left-and-ahead 90 1 [ left 90 ]
          fd 1
        ]
        die
      ]
      ask patches [ set plabel n ]
    end