8. Number Models 1

Number models, beginning to middle difficulty.
  1. A circle increases its radius by 5 every tick. Hitting a key reduces the radius by 50%.

  2. A square moves along a horizontal line. Every time you move the mouse, it moves right 1 pixel. When you hit a key it moves left 4 pixels.

  3. A small solid circle randomly moves between x=20, x=60, and x=100 on a fixed horizontal line. (You pick the $y$ coordinate.)

  4. Optional / too hard. Make the graph of $y=x(200-x)/50$. See below.

Optional: Graphing a function

Learn this method for graphing $y=f(x)$ using build-image.

  • Color points based on $c(x,y) = \left|y-f(x)\right|$.

  • When $c(x,y)=0$, the point $(x,y)$ is exactly on the graph, so you want it black.

  • Color based on $C = c(x,y)$. Black when C is 0, changing to white when C is (say) 5. Multiply by 255/5 = 51 in this case, because 5*51 = 255 of color = white.

  • Explore how changing the 51 changes the thickness of the line.

(define (c x y)
    (abs (- y (* 1/2 x))))
(define (c2 x y) 
    (abs (- (* 1/2 (- y 40) (- y 40)) x)))
(define (color-f x y)
    (gray (limit (* 51 (c x y)))))
(define (gray n)
    (make-color n n n))
(define (limit n)
    (max 0 (min 255 (real->int n))))
(build-image 200 100 color-f)
Last modified August 18, 2023: 2022-2023 End State (7352e87)