1.18.6 Drawing the Cat
This code is three large, similar constants, bundled up into the cat function. The thinking-cat is the one that is visible when the game is being played. It differs from the others in that it does not have a mouth. The mad-cat is the one that you see when the cat loses. It differs from the others in that its pinks turn pink. Finally, the happy-cat shows up when the cat wins and it is just like the thinking-cat except it has a smile.
(define/contract (cat mode) |
(-> (or/c 'mad 'happy 'thinking) image?) |
(define face-width 36) |
(define face-height 22) |
(define face-color |
(cond |
[(eq? mode 'mad) 'pink] |
[else 'lightgray])) |
(define left-ear |
(regular-polygon 3 8 'solid 'black (/ pi -3))) |
(define right-ear |
(regular-polygon 3 8 'solid 'black 0)) |
(define ear-x-offset 14) |
(define ear-y-offset 9) |
(define eye (overlay (ellipse 12 8 'solid 'black) |
(ellipse 6 4 'solid 'limegreen))) |
(define eye-x-offset 8) |
(define eye-y-offset 3) |
(define nose |
(regular-polygon 3 5 'solid 'black (/ pi 2))) |
(define mouth-happy |
(overlay (ellipse 8 8 'solid face-color) |
(ellipse 8 8 'outline 'black) |
(move-pinhole |
(rectangle 10 5 'solid face-color) |
0 |
4))) |
(define mouth-no-expression |
(overlay (ellipse 8 8 'solid face-color) |
(ellipse 8 8 'outline face-color) |
(rectangle 10 5 'solid face-color))) |
(define mouth |
(cond |
[(eq? mode 'happy) mouth-happy] |
[else mouth-no-expression])) |
(define mouth-x-offset 4) |
(define mouth-y-offset -5) |
(define (whiskers img) |
(add-line |
(add-line |
(add-line |
(add-line |
(add-line |
(add-line |
img |
6 4 30 12 'black) |
6 4 30 4 'black) |
6 4 30 -4 'black) |
-6 4 -30 12 'black) |
-6 4 -30 4 'black) |
-6 4 -30 -4 'black)) |
(whiskers |
(overlay |
(move-pinhole left-ear (- ear-x-offset) ear-y-offset) |
(move-pinhole right-ear (- ear-x-offset 1) ear-y-offset) |
(ellipse (+ face-width 4) (+ face-height 4) 'solid 'black) |
(ellipse face-width face-height 'solid face-color) |
(move-pinhole mouth (- mouth-x-offset) mouth-y-offset) |
(move-pinhole mouth mouth-x-offset mouth-y-offset) |
(move-pinhole eye (- eye-x-offset) eye-y-offset) |
(move-pinhole eye eye-x-offset eye-y-offset) |
(move-pinhole nose -1 -4)))) |
(define thinking-cat (cat 'thinking)) |
(define happy-cat (cat 'happy)) |
(define mad-cat (cat 'mad)) |