20. Tightrope

A square changes color as you balance between two circles.
  • There are two unmoving blue circles on the screen.

  • You can move a square with the mouse.

  • Square color is:

    • Green if the distance from the square to circle 1 and the distance from the square to circle 2 are within 20 of each other.
    • Red otherwise.

Some people had trouble understanding this description. In a computer-like language:

a = distance from square to circle 1
b = distance from square to circle 2
green if a and b are within 20 of each other

Write:

  1. Model
  2. The function square-color: model -> color.
Last modified August 18, 2023: 2022-2023 End State (7352e87)