Balloon lab PDF

Title Balloon lab
Course Computation, Programs, and Programming
Institution The University of British Columbia
Pages 5
File Size 39.4 KB
File Type PDF
Total Downloads 85
Total Views 141

Summary

Balloon lab...


Description

(require 2htdp/image) (require 2htdp/universe)

; Balloon popping

;; CONSTANTS ==========================

(define WIDTH 500) (define HEIGHT 500) (define MTS (empty-scene WIDTH HEIGHT))

(define BALLOON-COLOUR "red") (define BALLOON-MODE "solid") (define POP-IMAGE (overlay (text "POP!" 80 "black") (radial-star 30 (/ WIDTH 10) (/ WIDTH 2) "solid" "yellow"))) (define START 5)

(define CTR-X (/ WIDTH 2)) (define CTR-Y (/ HEIGHT 2))

(define SPEED 2)

(define MAX-SIZE (/ WIDTH 2))

;; DATA DEFINITIONS ============================

;; Balloon is one of: ;; - integer [5, MAX-SiZE] ;; - true ;; interp. true means popped, integer is radius of balloon

(define B1 true) (define B2 45)

#; (define (fn-for-balloon b) (cond [(number? b) (... b)] [(boolean? b) (...)])) ;; Template rules used: ;; - one of: 2 cases ;; - atomic non-distinct: integer[5, MAX-SIZE] ;; - atomic distinct: true

;; FUNCTIONS ====================================

;; Balloon -> Balloon ;; starts the world program with !!! ; no examples for main function

(define (main b) (big-bang b (on-tick tick) (to-draw render) (on-key handle-key)))

;; Balloon -> Balloon ;; expands the balloon by SPEED, until it is popped

(check-expect (tick B1) B1) (check-expect (tick 5) (+ 5 SPEED)) (check-expect (tick B2) (+ B2 SPEED)) (check-expect (tick MAX-SIZE) B1)

;(define (tick b) b);stub

; (define (tick b) (cond [(number? b) (if (> (+ SPEED b) MAX-SIZE ) true (+ SPEED b))] [(boolean? b) true]))

;; Balloon -> Image ;; draws the balloon of given size onto the MTS, unless popped (check-expect (render B1) (overlay POP-IMAGE MTS)) (check-expect (render 5) (overlay (circle 5 BALLOON-MODE BALLOON-COLOUR) MTS)) (check-expect (render B2) (overlay (circle B2 BALLOON-MODE BALLOON-COLOUR) MTS)) (check-expect (render MAX-SIZE) (overlay (circle MAX-SIZE BALLOON-MODE BALLOON-COLOUR) MTS))

;(define (render b) MTS);stub

; (define (render b) (cond [(number? b) (overlay (circle b BALLOON-MODE BALLOON-COLOUR) MTS)] [(boolean? b) (overlay POP-IMAGE MTS)]))

;; Balloon KeyEvent -> Balloon

;; changes balloon to true if space was pressed, resets on r (check-expect (handle-key B2 " ") B1) (check-expect (handle-key B2 "r") START) (check-expect (handle-key B2 "g") B2)

;(define (handle-key b) MTS);stub

;...


Similar Free PDFs