(require spd/tags) (require 2htdp/image) (require 2htdp/universe)
(@assignment lab-03) (@cwl ???)
; Balloon popping
is ar stu ed d vi y re aC s o ou urc rs e eH w er as o. co m
(@htdw Balloon)
;; CONSTANTS ==========================
(define WIDTH 500)
(define HEIGHT 500)
(define MTS (empty-scene WIDTH HEIGHT))
(define BALLOON-COLOR "red") (define POP-IMAGE
(overlay (text "POP!" 80 "black")
(radial-star 30 (/ WIDTH 10) (/ WIDTH 2) "solid" "yellow")))
(define CTR-X (/ WIDTH 2))
Th
(define CTR-Y (/ HEIGHT 2))
sh
(define SPEED 2)
(define MAX-SIZE (/ WIDTH 2))
This study source was downloaded by 100000805705997 from CourseHero.com on 10-14-2021 20:49:22 GMT -05:00
https://www.coursehero.com/file/57633285/Lab-3docx/
;; DATA DEFINITIONS ============================
(@problem 1)
(@htdd Balloon) ;; Balloon is one of ;; - false ;; - Number ;; interp. false means balloon has popped, number is the radius of the balloon
(define B1 0)
is ar stu ed d vi y re aC s o ou urc rs e eH w er as o. co m
;; CONSTRAINT: Number is in [0, MAX-SIZE)
;smallest balloon
(define B2 125)
;middle balloon
(define B3 250)
;max size of balloon
(define B4 false)
;popped balloon
(define (fn-for-balloon b) (cond [(false? b) (...)]
[(number? b) (... b)]))
(@dd-template-rules one-of atomic-distinct
;2 cases
;false
sh
Th
atomic-non-distinct) ;Number
;; FUNCTIONS ==================================== (@problem 2) (@htdf main) (@signature Balloon -> Balloon)
This study source was downloaded by 100000805705997 from CourseHero.com on 10-14-2021 20:49:22 GMT -05:00
https://www.coursehero.com/file/57633285/Lab-3docx/
;; starts the world program with (main 0) !!! ; no examples for main function (@template htdw-main)
(define (main b) (big-bang b
; Balloon
(on-tick tick)
; Balloon -> Balloon
(@problem 3) (@htdf tick)
; Balloon -> Image
is ar stu ed d vi y re aC s o ou urc rs e eH w er as o. co m
(to-draw render)))
(@signature Balloon -> Balloon)
;; produce the next balloon by adding SPEED every tick until it pops (check-expect (tick 0) (+ 0 SPEED)) (check-expect (tick 3) (+ 3 SPEED))
(check-expect (tick MAX-SIZE) false)
(check-expect (tick (- MAX-SIZE 1)) false) (check-expect (tick (- MAX-SIZE 2)) false) (check-expect (tick 251) false)
(check-expect (tick false) false)
Th
;(define (tick) 0) ;stub
(@template Balloon)
sh
;;<use template from Balloon>
(define (tick b) (cond [(false? b) b] [(number? b) (if (>= (+ b SPEED)
This study source was downloaded by 100000805705997 from CourseHero.com on 10-14-2021 20:49:22 GMT -05:00
https://www.coursehero.com/file/57633285/Lab-3docx/