On this page:
<drawing-the-cat>
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
    (rotate 34 (regular-polygon 8 3 'solid 'black)))
  (define right-ear
    (rotate -34 (regular-polygon 8 3 'solid 'black)))
  (define ear-x-offset 14)
  (define ear-y-offset -8)
 
  (define eye (underlay (ellipse 12 8 'solid 'black)
                        (ellipse 6 4 'solid 'limegreen)))
  (define eye-x-offset 8)
  (define eye-y-offset -3)
 
  (define nose
    (regular-polygon 5 3 'solid 'black))
 
  (define mouth-happy
    (overlay/align "center" "bottom"
                   (rectangle 0 8 'solid 'black)
                   (crop -1/2 4 9 5 (ellipse 8 8 'outline 'black))))
 
  (define mouth-no-expression
    (overlay/align "center" "bottom"
                   (rectangle 0 6 'solid 'black)
                   (rectangle 8 1 'solid 'black)))
 
  (define mouth
    (cond
      [(eq? mode 'happy) mouth-happy]
      [else mouth-no-expression]))
  (define mouth-x-offset 0)
  (define mouth-y-offset 5)
 
  (define (whiskers img)
    (define img-with-space
      (overlay img (rectangle (+ (image-width img) 20)
                              (image-height img)
                              "outline" "transparent")))
    (define whisker-start-y 17)
    (define whisker-start-right-x 32)
    (define whisker-start-left-x 24)
    (define whisker-width 23)
    (define whisker-y-delta 5)
    (add-line
     (add-line
      (add-line
       (add-line
        (add-line
         (add-line
          img-with-space
          whisker-start-left-x whisker-start-y
          (- whisker-start-left-x whisker-width)
          (- whisker-start-y whisker-y-delta) 'black)
         whisker-start-left-x whisker-start-y
         (- whisker-start-left-x whisker-width) whisker-start-y 'black)
        whisker-start-left-x whisker-start-y
        (- whisker-start-left-x whisker-width) (+ whisker-start-y whisker-y-delta) 'black)
       whisker-start-right-x whisker-start-y
       (+ whisker-start-right-x whisker-width) (- whisker-start-y whisker-y-delta) 'black)
      whisker-start-right-x whisker-start-y
      (+ whisker-start-right-x whisker-width) whisker-start-y 'black)
     whisker-start-right-x whisker-start-y
     (+ whisker-start-right-x whisker-width) (+ whisker-start-y whisker-y-delta) 'black))
 
  (whiskers
   (underlay/offset
    (underlay/offset
     (underlay/offset
      (underlay/offset
       (underlay/offset
        (underlay/offset
         (ellipse face-width face-height 'solid face-color)
         mouth-x-offset mouth-y-offset mouth)
        0 0 nose)
       (- eye-x-offset) eye-y-offset eye)
      eye-x-offset eye-y-offset eye)
     ear-x-offset ear-y-offset right-ear)
    (- ear-x-offset) ear-y-offset left-ear)))
 
(define thinking-cat (cat 'thinking))
(define happy-cat (cat 'happy))
(define mad-cat (cat 'mad))