number-spiral


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


WHAT IS IT?


-------
Create a spiral diagram of the integers.

Procedures

NetLogo Version: NetLogo 4.0.4

turtles-own
[ 
  r
  theta
  a
  prime?
]

to number-spiral [ #n ]
   ca
   ask patches [ set pcolor white ]
   message (word "Working. Generating " #n " points....")
   display
   let max-r sqrt #n
   let scale .49 * world-height / max-r 
   let def-size max (list 1 (scale * .5) )
   repeat #n
   [ create-turtles 1
     [ hide-turtle
       set color black
       set size def-size
       set r sqrt who
       set theta r
       set a (r * 360) mod 360
       let rs r * scale
       setxy (rs * cos a ) (rs * sin a  )
       set heading 0
       set prime? 1
       show-turtle
       if who mod 2500 = 0 [ display ]
     ]
   ]
   message ""
   display
end

to find-prime
   message (word "Seeking about " floor (count turtles * 0.16) " primes.")
   no-display
   let non-prime gray + 4
   
   if is-turtle? turtle 0 [ ask turtle 0 [ set prime? false set color non-prime] ]
   if is-turtle? turtle 1 [ ask turtle 1 [ set prime? false set color non-prime] ]
   
   let i 2
   let lim count turtles
   while [ i < lim ]
   [ if  is-turtle? turtle i and 1 = [ prime? ] of turtle i 
     [ ask turtle i [ set prime? true ] 
       let x i + i
       while [ x < lim ]
       [ ask turtle x [ set prime? false set color non-prime ]
         set x x + i
       ]
     ]
     set i i + 1
   ]
   message ""
   display
end
   
to id-number
   every .2
   [ ifelse ( mouse-inside? and mouse-down? )
     [ let mx mouse-xcor
       let my mouse-ycor
       ask (patch mx my) 
       [ if ( any? turtles-here )
         [ ask min-one-of turtles-here [ distancexy mx my ]
           [ message (word who ": r=" precision r 3 ", O=" precision theta 3 ) 
             display
           ]
         ]
       ]
     ]
     [ message ""
     ]

   ]  
end
              

to ask' [ anything ]
end

to kill-non-primes       
   no-display
   foreach [ self ] of turtles
   [ ask ? [ if prime? = false [ die ] ] ]
   display
   user-message (word count turtles " primes.")
end

to message [ text ]
   ask patch max-pxcor (max-pycor - .5 * world-height)
   [ set plabel-color black set plabel text ]
end     

      

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download number-spiral --