Advertisement
Guest User

Untitled

a guest
May 11th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. to setup
  2.   clear-all
  3.   set-default-shape turtles "square"
  4.   ;; make green atoms on left
  5.   ask patches with [pxcor < 0]
  6.     [ sprout 1 [ set color green ] ]
  7.   ;; make blue atoms on right
  8.   ask patches with [pxcor > 0]
  9.     [ sprout 1 [ set color blue ] ]
  10.   ;; plot the initial state of the system
  11.   reset-ticks
  12. end
  13.  
  14. to go
  15.   ;; asks vacancies to ask a neighboring atom to
  16.   ;; move into the vacancy
  17.   ask patches with [not any? turtles-here]
  18.     [ move-atom-to-here ]
  19.   tick
  20. end
  21.  
  22. ;; chooses a neighboring atom to move onto a empty patch (vacancy)
  23. to move-atom-to-here  ;; patch procedure
  24.   let atom one-of turtles-on neighbors4
  25.   if atom != nobody [
  26.     ask atom [ move-to myself ]  ;; myself is the calling patch
  27.   ]
  28. end
  29.  
  30. ;;; plotting procedures
  31.  
  32. to-report greens
  33.   report turtles with [color = green]
  34. end
  35.  
  36. to-report blues
  37.   report turtles with [color = blue]
  38. end
  39.  
  40. to plot-atoms [atoms]
  41.   plot-pen-reset
  42.   plot-pen-up
  43.   let column min-pxcor
  44.   repeat world-width [
  45.     let y count atoms with [pxcor = column]
  46.     plotxy column y
  47.     plot-pen-down
  48.     set column column + 1
  49.     plotxy column y
  50.   ]
  51. end
  52.  
  53.  
  54. ; Copyright 2007 Uri Wilensky.
  55. ; See Info tab for full copyright and license.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement