Moore & Von Neumann Example

Moore & Von Neumann Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner almost 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 857 times • Downloaded 88 times • Run 0 times
Download the 'Moore & Von Neumann Example' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Click to Run Model

globals [nearby]

to setup
  clear-all
  ;; use a global variable to store the offsets list so we
  ;; don't have to compute the same list (for a particular
  ;; radius) over and over again
  ifelse neighborhood-type = "Von Neumann"
    [ set nearby von-neumann-offsets radius include-central-patch? ]
    [ set nearby moore-offsets radius include-central-patch? ]
  ;; Now whenever a turtle or patch wants to refer
  ;; to its neighborhood, it says "patches at-points nearby".
  ;; A quick example:
  ask n-of 5 patches [
    sprout 1 [
      ;; see the entry for AT-POINTS in the NetLogo Dictionary
      ask patches at-points nearby [
        set pcolor [color] of myself
      ]
      set color white
    ]
  ]
end 

;; The next two procedures generate the lists of offsets that we pass to
;; AT-POINTS.
;;
;; When you paste this code into your model, if you know that you always
;; want to include the center, or never want to include it, you can remove
;; that parameter to make the code shorter.

;; examples of usage:
;; > print moore-offsets 1 true
;; [[-1 1] [1 1] [-1 -1] [-1 0] [1 0] [0 1] [0 0] [0 -1] [1 -1]]
;; > print von-neumann-offsets 1 true
;; [[0 1] [-1 0] [1 0] [0 0] [0 -1]]
;; for larger radii the results lists get long fast!

to-report moore-offsets [n include-center?]
  let result [list pxcor pycor] of patches with [abs pxcor <= n and abs pycor <= n]
  ifelse include-center?
    [ report result ]
    [ report remove [0 0] result ]
end 

to-report von-neumann-offsets [n include-center?]
  let result [list pxcor pycor] of patches with [abs pxcor + abs pycor <= n]
  ifelse include-center?
    [ report result ]
    [ report remove [0 0] result ]
end 


; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Moore & Von Neumann Example Download this version
Uri Wilensky over 14 years ago Moore & Von Neumann Example Download this version

Attached files

File Type Description Last updated
Moore & Von Neumann Example.png preview Preview for 'Moore & Von Neumann Example' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.