;; 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 18.1.1) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) (require picturing-programs) ; Exercise 18.1.1 (define WIDTH 300) (define HEIGHT 200) (define BACKGROUND (empty-scene WIDTH HEIGHT)) (define DOT (circle 3 "solid" "green")) ; Model is an image ; Mouse handler ; add-dot-on-mouse-down : image number(x) number(y) string(event) -> image (check-expect (add-dot-on-mouse-down BACKGROUND 35 10 "button-down") (place-image DOT 35 10 BACKGROUND)) (check-expect (add-dot-on-mouse-down BACKGROUND 35 10 "move") BACKGROUND) (define OTHER-BACKGROUND (ellipse 50 30 "solid" "red")) (check-expect (add-dot-on-mouse-down OTHER-BACKGROUND 35 10 "button-down") (place-image DOT 35 10 OTHER-BACKGROUND)) (check-expect (add-dot-on-mouse-down OTHER-BACKGROUND 35 10 "button-up") OTHER-BACKGROUND) (define (add-dot-on-mouse-down old x y event-type) ; old an image ; x a number (the x coordinate) ; y a number (the y coordinate) ; event-type a string (either "button-down" or not) ; DOT a fixed image we'll need) (cond [(string=? event-type "button-down") (place-image DOT x y old)] [else old])) (big-bang BACKGROUND (check-with image?) (on-draw show-it) (on-mouse add-dot-on-mouse-down))