Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. patches-own [
  2. living? ;; indicates if the cell is living
  3. live-neighbors ;; counts how many neighboring cells are alive
  4. ]
  5.  
  6. to setup-blank
  7. clear-all
  8. ask patches [ cell-death ]
  9. reset-ticks
  10. end
  11.  
  12. to setup-random
  13. clear-all
  14. ask patches
  15. [ ifelse random-float 100.0 < initial-density
  16. [ cell-birth ]
  17. [ cell-death ] ]
  18. reset-ticks
  19. end
  20.  
  21. to cell-birth
  22. set living? true
  23. set pcolor fgcolor
  24. end
  25.  
  26. to cell-death
  27. set living? false
  28. set pcolor bgcolor
  29. end
  30.  
  31. to cell-zombie
  32. set living? false
  33. set pcolor green
  34. end
  35.  
  36. to go
  37. ask patches
  38. [ set live-neighbors count neighbors with [living?] ]
  39. ;; Starting a new "ask patches" here ensures that all the patches
  40. ;; finish executing the first ask before any of them start executing
  41. ;; the second ask. This keeps all the patches in synch with each other,
  42. ;; so the births and deaths at each generation all happen in lockstep.
  43. ask patches
  44. [
  45. ifelse live-neighbors = 3 and pcolor != green
  46. [ cell-birth ]
  47. [
  48. ifelse live-neighbors = 7 [ cell-zombie ]
  49. [ if live-neighbors != 2 and pcolor != green
  50. [ cell-death ] ] ]]
  51. zombie-infection
  52. tick
  53. end
  54.  
  55. to draw-cells
  56. let erasing? [living?] of patch mouse-xcor mouse-ycor
  57. while [mouse-down?]
  58. [ ask patch mouse-xcor mouse-ycor
  59. [ ifelse erasing?
  60. [ cell-death ]
  61. [ cell-birth ] ]
  62. display ]
  63. end
  64.  
  65. to zombie-infection
  66. ask patches with [pcolor = green] [
  67. ask one-of neighbors [set pcolor green]]
  68. end
  69.  
  70.  
  71. ; Copyright 1998 Uri Wilensky.
  72. ; See Info tab for full copyright and license.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement