20.N Inventory
Good check-expects have no coincidences. Specifically, none of the inputs should be the same.
A. Linecheck
The function linecheck returns true if a posn is on the graph of a
particular line. The line is y=m*x+b, where m and b are inputs to
the fuction. The posn gives (x,y).
; linecheck : number(m) number(b) posn(p) -> boolean
-
Write two good
check-expectstatements, one with a true answer and one with a false answer. -
Write an inventory for
linecheck. -
Without using a conditional, write the code for
linecheck.
B. Distance-based Coloring
The bg-color function takes in a number(xline) and a posn, and
returns a color: “light blue” if the point is close to a specific
line, “orange” otherwise.
A star is on the line $y=\frac{3}{4}x+100$. The x-coordinate of the
star is given by the input xline. The input circle-p gives the
posn of the center of a circle. Return “orange” if the center of the
circle is less than 50 pixels from the center. Otherwise return “light
blue”.
An example function is below:
;; bg-color: number posn -> color
(define (bg-color xline circle-p)
(cond [(< (posn-distance (make-posn 80 160)
(make-posn 110 120))
50)
"orange"]
[else
"light blue"]))