(place-image txt lft top sce) ;; now let's make all of this independent of ;; the specific str and scene -------------- ;; specifics (define str "7th full week") (define scn (empty-scene 500 500)) ;; general (define width (image-width scn)) (define height (image-height scn)) (define tex (text str 36 "red")) (define lef (quotient width 2)) (define gap 20) (define tpp (* 3 (quotient (image-height tex) 2))) (define box (rectangle (+ (* 2 gap) (image-width tex)) (+ gap (image-height tex)) "outline" "black")) (place-image (overlay tex box) lef tpp scn) ;; now let's turn this into a function ------- ;; Scene String -> Scene ;; add the given string to the center of the scene (define (add-greeting scn str) (place-image (overlay (text str 36 "red") (rectangle (+ (* 2 gap) (image-width (text str 36 "red"))) (+ gap (image-height (text str 36 "red"))) "outline" "black")) (quotient (image-width scn) 2) (* 3 (quotient (image-height (text str 36 "red")) 2)) scn)) (check-expect (add-greeting scn str) (place-image (overlay tex box) lef tpp scn)) #| The agony of repetition ends: (local ((define ... ...) (define ... ...) (define ... ...)) ...) |# (define (+greeting scn str) (local ((define width ...) (define height ...) (define tex ...) (define lef ...) (define tpp ...) (define box ...)) (place-image tex lef tpp scn))) ;(check-expect (+greeting scn str) (place-image tex lef tpp scn))