; extensions [ jge ]
globals [ error ]
patches-own [ target_value cur_value ]

; -------------------------------
; Hieronder mag verwijderd worden
; -------------------------------

to test1
  simulate "(% (((y - x) * x) - (y * y)) 0.07) * x" true
end

to test2
  simulate "(% (x + y) 0.5)" true
end

to test3
  simulate "(% (x * y) 0.1)" true
end

to initialize 
  ;jge:load-bnf "grammar.txt" "grammar"
  ;...
end

; ------------------------
; Hieronder niet aanpassen
; ------------------------

to-report % [ numerator denominator ]
  report ifelse-value (denominator = 0) [ 1 ] [ numerator / denominator ]
end

to simulate [ f visible ]
  set f ifelse-value (empty? f) [ 0 ] [ f ] set error 0
  ask patches with [ pxcor < 30 ] [
    run (word "let x (pxcor - 14.5) / 30 let y (pycor - 14.5) / 30 set cur_value (" f ")"
      ifelse-value visible [ (word "set pcolor num-to-rgb (" f ")") ][ "" ])
    set error error + abs (target_value - max list -1 (min list 1 cur_value))
  ]
end

to setup
  ca
  ask patches with [ pxcor > 30 ] [
     let n (12 * pxcor ^ 2 - 1092 * pxcor + 8 * pycor ^ 2 - 232 * pycor + 23105) / 3600
     ask patch-at -31 0 [ set target_value n ]
     set pcolor num-to-rgb n
  ]
  initialize
end

to-report num-to-rgb [ num ]
  let n 255 * max list -1 (min list 1 abs num)
  report ifelse-value (num < 0) [ rgb n (255 - n) 0 ] [ rgb 0 (255 - n) n ]
end
@#$#@#$#@
GRAPHICS-WINDOW
190
70
810
401
-1
-1
10.0
1
10
1
1
1
0
0
0
1
0
60
0
29
0
0
1
ticks

MONITOR
190
10
415
55
Error:
error
17
1
11

BUTTON
40
130
106
163
Test 1
test1
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL

BUTTON
110
130
176
163
Test 2
test2
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL

BUTTON
40
170
106
203
Test 3
test3
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL

BUTTON
40
70
110
103
Set-Up
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL

@#$#@#$#@
WHAT IS IT?
-----------
This section could give a general understanding of what the model is trying to show or explain.


HOW IT WORKS
------------
This section could explain what rules the agents use to create the overall behavior of the model.


HOW TO USE IT
-------------
This section could explain how to use the model, including a description of each of the items in the interface tab.


THINGS TO NOTICE
----------------
This section could give some ideas of things for the user to notice while running the model.


THINGS TO TRY
-------------
This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.


EXTENDING THE MODEL
-------------------
This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.


NETLOGO FEATURES
----------------
This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab.  It might also point out places where workarounds were needed because of missing features.


RELATED MODELS
--------------
This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.


CREDITS AND REFERENCES
----------------------
This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.
@#$#@#$#@
default
true
0
Polygon -7500403 true true 150 5 40 250 150 205 260 250

@#$#@#$#@
NetLogo 4.1.3
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
default
0.0
-0.2 0 1.0 0.0
0.0 1 1.0 0.0
0.2 0 1.0 0.0
link direction
true
0
Line -7500403 true 150 150 90 180
Line -7500403 true 150 150 210 180

@#$#@#$#@
0
@#$#@#$#@
