Java StarLogo 1.1 `turtle` `observer` globals [ gd ] ;; all the magic mumbers, encapsulated to gd-focus output 1 end to gd-midfldr output 2 end to gd-towns output 3 end to gd-travs output 4 end to gd-ersrs output 5 end to gd-size output 40 end to towns-def output 6 end to travs-def output 3 end to ersrs-def output 2 end to midfldr-def output 1 end to empty-list output (butfirst (butfirst (list 1 2))) end to setup ca let [:my-gd (list-of-zeros gd-size)] ;; To avoid constant nattering from the software, ;; about passing 0 to item as an index, give the ;; focus element of gd an initial value pointing ;; to the end of the list. There is a bad race ;; condition here, between the monitor sampling ;; setting and the setup execution time. ;; A complex test in the get-gd accessor for the ;; global list gd protects against the race ;; condition, at a cost in time and complexity. setgd :my-gd let [:my-gd (my-setitem gd-focus :my-gd gd-size)] ;; DB-SHOW :my-gd let [:my-gd (set-defaults :my-gd)] ;; DB-SHOW :my-gd setgd :my-gd end to DB-SHOW :thing ;; DEBUG let [:my-thing :thing] print :my-thing end to list-of-zeros :how-long let [:my-list empty-list] repeat :how-long [ let [:my-list lput 0 :my-list] ] output :my-list end to my-setitem :some-index :some-list :some-element let [:my-index :some-index] let [:my-list :some-list] let [:my-element :some-element] let [:list-length (length :my-list)] let [:rep-count 0] repeat (:list-length) [ let [:rep-count (1 + :rep-count)] ifelse (:rep-count = :my-index) [ let [:my-list (lput :my-element (butfirst :my-list))] ] [ let [:my-list (lput (first :my-list) (butfirst :my-list))] ] ] output :my-list end to set-defaults :some-gd let [ :my-gd :some-gd ] let [ :my-gd ( my-setitem gd-midfldr :my-gd midfldr-def ) ] let [ :my-gd ( my-setitem gd-towns :my-gd towns-def ) ] let [ :my-gd ( my-setitem gd-travs :my-gd travs-def ) ] let [ :my-gd ( my-setitem gd-ersrs :my-gd ersrs-def ) ] output :my-gd end to initialize print [pressed initialize] end to go print [turn off go button please] wait 5 end to get-gd :index let [ :my-gd gd ] let [ :my-index :index ] ;; protect complexly against sampling before setup is done. if ( list? :my-gd ) [ if ((:my-index > 0) and (:my-index <= gd-size)) [ if ((length :my-gd) = gd-size) [ output item :my-index :my-gd ] ] ] ;; not ready yet for one reason or another, give back a ;; recognizable "something might be wrong" value. output (0 - 999999.999) end to put-gd :index :value let [:my-gd gd] let [:my-gd (my-setitem :index :my-gd :value)] ;; DB-SHOW :my-gd setgd :my-gd end to show-value-at-focus output (get-gd (get-gd gd-focus)) end to get-focus output get-gd gd-focus end to put-focus :focus put-gd gd-focus :focus end to chg-num-at-focus :chg let [ :my-val (get-gd (get-gd gd-focus)) ] let [ :my-val ( :my-val + :chg ) ] put-gd (get-focus gd-focus) :my-val end `information` ================ sliderless.slogo ================ What is this stuff? ------------------- Example code, not a complete application. Where is the most recent version of the code? --------------------------------------------- http://www.well.com/user/xanthian/public/code/StarLogo/how2/sliderless.slogo Can I steal the code? --------------------- Yes. This is freeware, and is placed by the author in the public domain. Do with it whatever you like. Who wrote it? ------------- Kent Paul Dolan xanthian@well.com http://www.well.com/user/xanthian Why does it exist? ------------------ To be an example of providing an easier user interface to enter higher precision data to StarLogo applications than feasible with the use of (jittery) sliders. To be an example of abstracting data by encapsulating "magic number" constants in named routines that produce those constants to avoid a mass of globals cluttering up the program. What does it do? ---------------- Not much. First you do some setup stuff. Then, you press one of four buttons to select a data item to increment or decrement or clear, do so with a single interface for any of the four modifiable values, and the changing values are displayed on a single monitor. That's about it. Just a proof of concept for using data abstraction, and for jitterless higher precision data input. What do I see on the screen? ---------------------------- Conceptually: A three stage setup: do initialization and set defaults, let the user modify the defaults if desired, then use the default or user modified values to complete setup. Physically: An initial setup button that builds a list of zeros in the one and only global variable, gd, then does some fudging and default setting to keep the user interface data in a consistant state. An apply settings button that just prints out "initialize", but in a working application would take the data as entered by the user, and apply it in a form suitable for use in the running program, perhaps by scaling from integer to real, perhaps by creating entities or doing other further setup actions based on the value provided by the user. A go button which just prints a "turn me off" message to the output window every once in a while, but in a working application would set the threads of control in motion. A single monitor to display whatever value is being modified, surrouneded by some increment and decrement buttons, in powers of four steps because that seemed more friendly than powers of ten, and one clear button to provide a fast path back to zero. Four data value choice buttons in a vertical column to select which data value is being modified and displayed at the current time. A couple of debug buttons on the bottom, one to dump the global data list, and one to clear the finite capacity output window. A tiny patch screen, left in but made small to save storage. It is not used in this example. Enjoy, comments are welcome. `interface` SLButton turtle-or-observer? observer top-left 195 51 width-height 40 30 name ">>" line-to-run "chg-num-at-focus 4" forever? false button-number 9 show-name? true SLButton turtle-or-observer? observer top-left 158 239 width-height 40 30 name "clear" line-to-run "put-gd (get-gd gd-focus) 0" forever? false button-number 22 show-name? true SLButton turtle-or-observer? observer top-left 339 11 width-height 47 30 name "ersrs" line-to-run "put-focus gd-ersrs" forever? false button-number 15 show-name? true SLButton turtle-or-observer? observer top-left 305 11 width-height 45 30 name "travs" line-to-run "put-focus gd-travs" forever? false button-number 14 show-name? true SLButton turtle-or-observer? observer top-left 271 10 width-height 46 30 name "towns" line-to-run "put-focus gd-towns" forever? false button-number 13 show-name? true SLButton turtle-or-observer? observer top-left 235 11 width-height 47 30 name "midfldr" line-to-run "put-focus gd-midfldr" forever? false button-number 12 show-name? true SLButton turtle-or-observer? observer top-left 7 13 width-height 212 30 name "DO INITIAL SETUP" line-to-run "setup" forever? false button-number 1 show-name? true SLButton turtle-or-observer? observer top-left 123 60 width-height 45 30 name "<<<<<" line-to-run "chg-num-at-focus (0 - 256)" forever? false button-number 18 show-name? true SLButton turtle-or-observer? observer top-left 195 184 width-height 47 30 name ">>>>>" line-to-run "chg-num-at-focus 256" forever? false button-number 20 show-name? true SLButton turtle-or-observer? observer top-left 195 137 width-height 44 30 name ">>>>" line-to-run "chg-num-at-focus 64" forever? false button-number 11 show-name? true SLButton turtle-or-observer? observer top-left 77 14 width-height 210 34 name "MAKE IT GO!" line-to-run "go" forever? true button-number 3 show-name? true SLButton turtle-or-observer? observer top-left 383 106 width-height 79 30 name "clear output" line-to-run "co" forever? false button-number 17 show-name? true SLButton turtle-or-observer? observer top-left 382 11 width-height 82 30 name "SHOW GD" line-to-run "DB-SHOW gd" forever? false button-number 16 show-name? true SLButton turtle-or-observer? observer top-left 123 11 width-height 46 30 name "<<<<<<" line-to-run "chg-num-at-focus (0 - 1024)" forever? false button-number 19 show-name? true SLButton turtle-or-observer? observer top-left 123 108 width-height 40 30 name "<<<<" line-to-run "chg-num-at-focus ( 0 - 64 )" forever? false button-number 4 show-name? true SLButton turtle-or-observer? observer top-left 123 152 width-height 40 30 name "<<<" line-to-run "chg-num-at-focus (0 - 16)" forever? false button-number 5 show-name? true SLButton turtle-or-observer? observer top-left 123 239 width-height 40 30 name "<" line-to-run "chg-num-at-focus (0 - 1)" forever? false button-number 7 show-name? true SLButton turtle-or-observer? observer top-left 123 196 width-height 40 30 name "<<" line-to-run "chg-num-at-focus (0 - 4)" forever? false button-number 6 show-name? true SLButton turtle-or-observer? observer top-left 43 12 width-height 212 30 name "APPLY USER SETTINGS [ ONCE! ]" line-to-run "initialize" forever? false button-number 2 show-name? true SLButton turtle-or-observer? observer top-left 195 94 width-height 40 30 name ">>>" line-to-run "chg-num-at-focus 16" forever? false button-number 10 show-name? true SLButton turtle-or-observer? observer top-left 194 9 width-height 40 30 name ">" line-to-run "chg-num-at-focus 1" forever? false button-number 8 show-name? true SLButton turtle-or-observer? observer top-left 195 233 width-height 47 30 name ">>>>>>" line-to-run "chg-num-at-focus 1024" forever? false button-number 21 show-name? true SLMonitor top-left 155 11 width-height 224 36 name "VALUE BEING CHANGED" list-to-run "show-value-at-focus" digits 3 delay 0.3 monitor-number 1 show-name? true SLCanvas top-left 4 286 `settings` patch-size 4 num-shapes 256 screen-half-width 2 screen-half-height 2 interface-window-xcor 211 interface-window-ycor -2 interface-window-size 343 426 output-window-xcor 284 output-window-ycor 297 output-window-width 678 output-window-height 152 info-window-xcor 144 info-window-ycor 54 info-window-width 595 info-window-height 419 control-center-xcor 566 control-center-ycor 1 control-center-width 300 control-center-height 419 turtle-command-center-height 138 observer-command-center-height 138 plot-window-xcor 0 plot-window-ycor 0 plot-window-width 508 plot-window-height 372 `string table` H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA== `symbol table` H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA== `double table` H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA== `list table` H4sIAAAAAAAAAGNgYGAAABzfRCEEAAAAAAAABA== `observer world` H4sIAAAAAAAAAGMQSMhPKk4tKkstUiguSSxJTXBggAMtBm6wWE5qXnpJBlCAhYEN zuZgYC/IyS8pSM2DqmZkYEpPgbEZgQQAePnrz1wAAAAAAABc `patch world` H4sIAAAAAAAAAH3OwQrCMAwG4DiGBkTIIQcPHnwTd/I5Nkpxh7EV7UHf2kewbLYO bP9CSMhX2p8Oreu86c8P33nbNpTOlfbzbrDjzfdhcaLtaq6fZrrPF3dumLyzYxiP VL+WNVPlTOgSqvoWXd7L07Gvzib+nDUGJsC0bHHX/NEvS9YYmADTsqUsDLLkjIEJ MC1byiIgS84YmADTsqUsCrLkjIEJMC3bB8p5hjspAwAAAAADKQ== `turtle world` H4sIAAAAAAAAAGPgSygpLSrJSVUoLkksSU1wYICDfgaOgtS8lPzyvAIgz4iBrTgD yjZmYE3Oz8kvAjJlGLjBGnNS89JLMoACJgxsSGz2jNTElMy8dCBHhIGlIhmsh4WB vSAnvwRoOJCjx8BSCRHmYWAuz8gHW82aVJSamgJkqDCwFmckFqQCmVowd/0HAhAN AOCz5dm7AAAAAAAAuw==