20. Click Circle

Exercises 20.6.3 and 20.6.4.

check-with

The clause (check-with posn?) makes sure that every handler returns a posn. You should add this clause to your big-bang whenever you work with posns. Colors have a similar check, color?.

Stop-when

There is a new clause in big-bang called stop-when. It works like the linked demo code. The big-bang looks like this:

(big-bang 0
          (on-tick add1 0.1)
          (on-draw draw-num 300 200)
          (stop-when above-ten? draw-done))

The above-ten? method takes in a model and produces a boolean value. The big-bang stops if this function returns true.

The draw-done method is a draw handler called when to produce the last frame of the animation - regarless of why the big-bang is ending.

Impossible State Trick

One way to decide that an animation is over is to change the model to something that is impossible under regular circumstances. For example, a posn with negative coordinates could not be created by the mouse-handler under normal circumstances, so it could be used to indicate that the animation should end.

(define MODEL-END-IT (make-posn -1001 999))
(define (stopping? model) 
  (posn=? model MODEL-END-IT))

Notes