Newer
Older
This is an example project to demonstrate Literate Programming to create [NetLogo](https://ccl.northwestern.edu/netlogo/) models from ODD+C protocols.
### Entities, state variables, and scales
```netlogo
;- State variables
patches-own [
state
]
```
```netlogo
;- Disease states
globals [
EMPTY
S
I
R
]
```
;- Setup disease states
set EMPTY 0
set S 1
set I 2
set R 3
### Process overview and scheduling
clear-all
; ==> Setup disease states.
update-patches
#### Visualization
```netlogo
;- Update patches
to update-patches
ask patches [
ifelse state = EMPTY [ set pcolor white ]
[ ifelse state = S [ set pcolor blue ]
[ ifelse state = I [ set pcolor red ]
[ set pcolor green ] ] ]
]
end
```
### Code
```netlogo
;- file:Code.nls
; ==> Disease states.
; ==> State variables.
; ==> Setup.
; ==> Go.
```
### NetLogo file
In the main `nlogo` file, we only "include" an `nls` file to allow for the reverse mode.
The file `Model.nlogo` is simply copied from the `nlogo` directory via option `code_files` in the `[paths]` section of the `Yarner.toml`.
This separation of model code and user interface also allows to edit the model's UI elements in NetLogo's GUI builder tool, while using Literate Programming for the code.