Loading ...
Sorry, an error occurred while loading the content.
 

Re: [netlogo-users] Cars and Roads model

Expand Messages
  • Jim Lyons
    ... Seth, Thanks for the tip! This is very smooth. I have been using the new agentset reporters in my code -- no-turtles, no-patches, turtle-set, patch-set --
    Message 1 of 5 , Dec 1, 2007
      On Nov 30, 2007, at 5:39 PM, Seth Tisue wrote:

      > > let $choices filter [is-patch? ? and [pcolor] of ? = blue]
      > > (list(patch-left-and-ahead 90 1)(patch-ahead
      > 1)(patch-right-and-ahead 90 1))
      > > ifelse empty? $choices [ right 180 ] [ face one-of $choices jump 1 ]
      >
      > I'd suggest writing this part using agentsets instead of lists.
      > If you define this helper procedure:
      >
      > to-report patches-ahead
      > report (patch-set patch-left-and-ahead 90 1
      > patch-ahead 1
      > patch-right-and-ahead 90 1)
      > end
      >
      > then you can write:
      >
      > let $choices patches-ahead with [pcolor = blue]
      > if any? $choices [ ... ]
      >
      > thereby avoiding IS-PATCH?, FILTER, OF, and ?.

      Seth,
      Thanks for the tip! This is very smooth. I have been using the new
      agentset reporters in my code -- no-turtles, no-patches, turtle-set,
      patch-set -- just not quite enough I guess. ;^)

      Below is the smoother version for those who want to paste and play. I
      also took out one line in the turtles loop so that now if you draw a
      road next to the turtle, it hops on the road and starts following it.

      Jim Lyons
      ---------
      to startup
      clear-all
      ask patches [ set pcolor gray ]
      create-turtles 1 [ set color red set heading 0 ]
      end

      to go ;by observer, forever
      if mouse-down? ; allow user to draw/erase roads on the patches
      [ let $c ifelse-value ([pcolor] of patch mouse-xcor mouse-ycor =
      gray)[blue][gray]
      while [mouse-down?] [ ask patch mouse-xcor mouse-ycor [ set pcolor
      $c ] ]
      ]
      every .2 [ ask turtles
      [ let $choices (patch-set (patch-left-and-ahead 90 1)
      (patch-ahead 1)(patch-right-and-ahead 90 1)) with [pcolor = blue]
      ifelse any? $choices [ face one-of $choices jump 1 ] [ right 180 ]
      ]]
      end
    • Ola Olsson
      This is a naive question about the various buttons (gadgets) available for the interface. Is there a way to access their event handler? For example: when I
      Message 2 of 5 , Dec 13, 2007
        This is a naive question about the various buttons (gadgets)
        available for the interface. Is there a way to access their event
        handler? For example: when I change the color in a list gadget can I
        have it trigger a procedure immediately? Or can I bind the buttons to
        procedures or other buttons so that there is immediate feedback when
        values are changed?

        Best Regards,
        Ola Olsson
      • James Steiner
        Hi, Ola. You asked if one can access the event handlers of controls in the interface pane. In short: No, one can not. In long: You can write procedures that
        Message 3 of 5 , Dec 14, 2007
          Hi, Ola.

          You asked if one can access the event handlers of controls in the
          interface pane. In short: No, one can not.

          In long: You can write procedures that detect and act on changes in
          the interface, then use monitors in the interface to periodically run
          that code, wrapped in a reporter. You can hide these monitors, if
          desired, underneath other controls or nearly empty "note" controls.

          You' will get nearly the same effect.

          For example, to monitor changes in a slider:

          ;; assumes slider is called "patch-color"
          globals [ old-patch-color ]

          to startup
          set old-patch-color patch-color
          end

          to detect-patch-color-changes
          if old-patch-color != patch-color
          [ activate-patch-color-slider-change-handler
          set old-patch-color patch-color
          ]
          end

          to-report change-detect-wrapper
          ;; this goes in a monitor, so it is run periodically,
          ;; even when nothing else is happening
          detect-patch-color-changes
          ;; followed by any other "detect-___-changes" procedures
          report "" ;; report a blank
          end

          to activate-slider-patch-color-slider-change-handler
          ;; whatever you want to do when the slider changes
          end

          ============

          You can use similar techniques to detect button pushes and changes in
          choosers and inputs.

          Now, monitor code tends to run about 10 times a second, when nothing
          else is happening. This is usually frequent enough to effectively
          capture and react to user input. I have a full GUI drag-n-drop in-view
          network editor that is slow, but functional, even when only running
          from the monitor.

          You can also use similar techniques to detect whether a particular
          forever-button is active. In a nutshell: Setup sets a global variable
          to false. The forever button routine sets that variable to TRUE. The
          monitor sets the same variable to FALSE at the end. .So, if at the
          start of the monitor code the variable is FALSE, that means that the
          forever button didn't set the variable to TRUE, and that means the
          button is not down.

          You can use a similar technique to allow two forever buttons to keep
          track of each other, or only allow one of two forever buttons to be
          down at the same time.

          Hope this helps,

          ~~James
          ___________________
          http://www.turtlezero.com



          On Dec 13, 2007 9:51 PM, Ola Olsson <oeolsson@...> wrote:
          > This is a naive question about the various buttons (gadgets)
          > available for the interface. Is there a way to access their event
          > handler? For example: when I change the color in a list gadget can I
          > have it trigger a procedure immediately? Or can I bind the buttons to
          > procedures or other buttons so that there is immediate feedback when
          > values are changed?
          >
          > Best Regards,
          > Ola Olsson
        Your message has been successfully submitted and would be delivered to recipients shortly.