store a randomly produced grid
- store a randomly produced grid
to produce a random grid of plants (green) i use a slider for density
and the procedure
if (random 100) < density
[ set pcolor green]]
in order to present different outcomes of my model for different
inputs i also would like to have one fixed environment for certain
therefor my question is:
is it somehow possible to store a randomly created environment?
if yes -> what must i do?
thanks in advance
> therefor my question is:Yes.
> is it somehow possible to store a randomly created environment?
> if yes -> what must i do?
I can think of three options right off:
First: stored random seed
If you seed the random number generator with the same number, you get the
So, you can generate a particular, same-every-time setup by using that
;; assume slider called density, varying from 0 to 100
;; assume switch called use-preset?
[ ; for no reason, using the density to seed the RNG.
; could use any single number or range of numbers
; doesn't really matter
ifelse [ random 100 < density ]
[ set pcolor green ]
[ set pcolor black ]
Second: stored values in list, saved to csv (or otherwise)
A second method would involve generating a random environment with a
particular density, storing the results in a patch-owned list variable, then
saving the list (via export-world, for example).
;; assume patches-own e-list
Locals [ index ]
[ ;; blank list
set e-list 
; initial index
Set index 0
; generate list
[ ; set the density slider
set density index
; set the patch colors
; store the current patch color in the list
[ set e-list lput pcolor e-list ]
; increment the index
set index index + 1
;; put distinctive colors in patches to make it clear that
;; this is not a valid initial invironment
Ask patches [ set pcolor blue - 3 + random 7 ]
To retrieve the preset, first import-world the list, then, as needed:
;; assume a button called "fetch preset" that runs this code
;; using the density slider to select the preset value
[ set pcolor item density e-list ]
The third way would be to use an algorithm to generate the preset.
I don't know the math involved, but I'm thinking of the sort of
integer-based non-random dithering algorithm that is/was used on 16-color
and 256-color displays to simulate higher color depths. Or a half-toning
algorithm. Like that.
Hope this helps!
This email has been scanned for all viruses by the MessageLabs Email