Popup HUD - part 1 of 2

Popup HUD - part 1 of 2 preview image

This model is seeking new collaborators — would you please help?

1 collaborator

Army_coat_pix R. Wade Schuette (Author)

Tags

hud 

"pop up HUD with hide/show option to control a model"

Tagged by R. Wade Schuette over 2 years ago

levelspace 

Tagged by R. Wade Schuette over 2 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.2.2 • Viewed 338 times • Downloaded 11 times • Run 0 times
Download the 'Popup HUD - part 1 of 2' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; model version 1.0,  June 16, 2022

extensions [ ls ]
globals [
          ;;============= HUD related golbals
          HUD         ;; model-ID reference
          HUD-state   ;; none, idle, ready
          safety-delay-seconds;; wait time after an update, possibly not needed


          ;;============== variables in my main model
          ;;   named differently from the HUD so it's clear which is which
          number-T
          size-T
          shape-T
]

to setup
  clear-all

  ;; ====== HUD RELATED commands
  set HUD-state "none"
  set safety-delay-seconds 0

  ;; ======= normal model commands
  ;; local version of these variables
  set number-T 3
  set size-T 3
  set shape-T "circle"


  create-turtles number-T [
      set size  size-T
      set shape shape-T
      set xcor random-xcor
      set ycor random-ycor
    ]

  reset-ticks
end 

to go
  if not ( HUD-state = "none") [ check-HUD ]   ;; The only HUD command in the GO loop

  ;; === usual model commands go next
  ask turtles [ set heading random 360 forward 1 ]

  tick
end 

;; ========= HUD related CODE begins here ====================================
;;
;; NOTE:  all the subroutines are named -HUD
;;
;;        "HUD" is not a magic word.  The Head's Up Display could
;;        be called "apple" everywhere on both ends and this would still run.
;;
;; NOTE:  all HUD interactions are driven by the model
;;        the HUD never asks the model to do anything.
;;        IN fact, the HUD has zero LevelSpace code in it and
;;        doesn't even list the "ls" extension.

;;  inbound commands, getting data FROM the HUD are like this:
;;    substituting your values for "< something > "
;;
;;  pattern: set  [ HUD-variable ] ls:of HUD
;;  example:  set size-T    [size-of-turtles ]   ls:of HUD
;;
;;   outbonund commands, setting a HUD variable from the model are like this:
;;   pattern:  ls:assign HUD   
;;   example:  ls:assign HUD status "idle"
;;
;;  or to run a HUD subroutine from the model
;;  pattern:    ls:ask HUD [ < hud subroutine name > ]
;;  example:    ls:ask HUD [ mark-update-complete ]

to check-HUD
   set HUD-state  [status] ls:of HUD
   ;print (word "HUD-state is " HUD-state)
   if HUD-state = "ready"
     [
       set number-T  [number-of-turtles ] ls:of HUD
       set size-T    [size-of-turtles ]   ls:of HUD
       set shape-T   [shape-of-turtles ]  ls:of HUD
       ask turtles [die]
       create-turtles number-T[
          set size  size-T
          set shape shape-T
          set xcor random-xcor
          set ycor random-ycor
       ]
       ls:assign HUD status "idle"
       set HUD-state  [status] ls:of HUD
      ls:ask HUD [ mark-update-complete ]
     ]
    wait safety-delay-seconds
end 

to  start-HUD  ;; ?? are there dead models ???
  if not ( HUD-state = "none") [ print "Destroying current HUD and starting fresh."]
  ls:reset
  startup-HUD
  setup-HUD
  check-HUD
end 

to startup-HUD
  ;; this code expects callable-HUD.nlogo to be in the same directory as this model
  ;; if that is not true the path in the following line needs to be adjusted
  ls:create-interactive-models 1 "./callable-HUD.nlogo"
  set HUD last ls:models
end 

to setup-HUD
  ls:ask HUD [ setup ]   ; calls setup in all models in LevelSpace
  ls:assign HUD status "idle"
  reset-ticks ; now we're ready to go, so reset ticks
end 

to show-HUD
  ifelse  not (HUD-state = "none") [ ls:show HUD ][ print "There is no HUD to show!"]
end 

to hide-HUD
    ifelse  not (HUD-state = "none") [ ls:hide HUD ][ print "There is no HUD to hide!"]
end 

to remove-HUD
    ifelse  not (HUD-state = "none") [
      ls:close HUD
      set HUD-state "none"
    ][ print "There is no HUD to remove!"]
end 

;; =========================== HUD RELATED CODE ENDS =========================

;  carefully [] might come in handy



; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There is only one version of this model, created over 2 years ago by R. Wade Schuette.

Attached files

File Type Description Last updated
Popup HUD - part 1 of 2.png preview Preview for 'Popup HUD - part 1 of 2' over 2 years ago, by R. Wade Schuette Download

This model does not have any ancestors.

This model does not have any descendants.