U WS 02

You are going to make a universe animation where each window shows a counter increasing by 0.5 every 0.5 seconds (a timer).

  • Hitting a key in a window stops that window’s timer.
  • Clicking in a window starts that window’s timer and stops every other window’s timer.

The model to use is the structure A, which has

  • id: a positive integer, like 1, 2, 3…
  • t: a number, the time in seconds for that window
  • run?: a boolean, true if timer is running

The message to use is the structure B, which has

  • from: a positive integer, the id of the sender
  • cmd: a number for your own purpose

The starter code for these structures is:

; Model
(define-struct a (id t run?))
(define-struct b (from cmd))

Exercises

  1. Make an example world called ex1.
  2. The tick handler th has two different behaviors, depending on whether or not the timer is running. Write one check-expect for each of these behaviors.
  3. Write a check-expect for the key handler kh.
  4. Write a check-expect for the mouse handler mh showing what happens when you click in the window.
  5. The receive handler is called rh. What is the signature of rh?
  6. Write code for the receive handler rh.
Last modified August 18, 2023: 2022-2023 End State (7352e87)