(require 2htdp/image) ;; ------------------------------------------------------- ;; define a function that eliminates those Posns from a list ;; whose x or y coordinate is smaller than 0 or larger than ;; 100 ;; [List-of Posn] -> [List-of Posn] ;; eliminates ,,, 100 (check-expect (bad-bullets (list (make-posn 50 50) (make-posn 150 50) (make-posn 0 -1))) (list (make-posn 50 50))) (define (bad-bullets a-lop) (local (;; (Posn -> Boolean) ;; those items on alox for which p holds ;; giveen wanted ;; (make-posn 50 50) true ;; (make-posn 150 50) false ;; (make-posn -1 0) false (define (p? p) (and (<= 0 (posn-x p) 100) (<= 0 (posn-y p) 100)))) ;; (Posn -> Boolean) [List-of Posn] -> [List-of Posn] (filter p? a-lop))) ;; ----------------------------------------------------------------------------- ;; define a function that places a yellow star of size 5 at each ;; Posn on some list on some blue 200 x 200 background ;; [List-of Posn] -> Image ;; places ... background (check-expect (create-sky (list (make-posn 50 50) (make-posn 0 100))) (place-image (star 5 'solid 'yellow) 50 50 (place-image (star 5 'solid 'yellow) 0 100 (rectangle 200 200 'solid 'navy)))) (define (create-sky a-lop) (local (;; (Posn Image -> Image) ;; apply f to the last item in alox and base, and so on ;; given wanted ;; (make-posn 50 50) e (place-image ...star... 50 50 e) ;; (make-posn 0 100) e (place-image ...star 0 100 e) (define (f p i) (place-image (star 5 'solid 'yellow) (posn-x p) (posn-y p) i)) (define e (rectangle 200 200 'solid 'navy))) ;; (Posn Image -> Image) Image [List-of Posn] -> Image (foldr f e a-lop)))