;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname 8.4.1) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) (require picturing-programs) ; Worked exercise 8.4.1 ; Model: a number representing the x coordinate of the calendar ; Assumes you did exercise 8.2.2 or 8.3.3, producing a draw handler named calendar-at-x. (define (calendar-at-x x) (place-image pic:calendar x 50 (rectangle 500 100 "solid" "white"))) ; Mouse handler: ; add1-on-mouse : number(x) number(mouse-x) number(mouse-y) event -> number (check-expect (add1-on-mouse 3 29 348 "blarg") 4) (check-expect (add1-on-mouse 15 503 6 "glink") 16) (define (add1-on-mouse x mouse-x mouse-y event) ; x number ; mouse-x number (ignore) ; mouse-y number (ignore) ; event whatever (ignore) (+ x 1) ; or, if you prefer, (add1 x) ) ; sub2-on-key : number (x) key -> number (check-expect (sub2-on-key 7 "dummy argument") 5) (check-expect (sub2-on-key 2 "whatever") 0) (define (sub2-on-key x key) ; x number ; key whatever (ignore) (- x 2) ) (big-bang 250 (on-draw calendar-at-x) (on-mouse add1-on-mouse) (on-key sub2-on-key))