-
Notifications
You must be signed in to change notification settings - Fork 6
/
ex-153.rkt
83 lines (63 loc) · 1.63 KB
/
ex-153.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#lang htdp/bsl
(require 2htdp/image)
(require 2htdp/universe)
; A N is one of:
; - 0
; - (add1 N)
; A Balloon is a Posn
; A List-of-balloons is one of:
; - '()
; - (cons Balloon List-of-balloons)
(define my-square (square 10 "outline" "black"))
(define balloon (circle 3 "solid" "red"))
; N Image -> Image
; Generates a new image that consists of n times img placed vertically
(check-expect (image-width (col 0 my-square)) 0)
(check-expect (col 1 my-square) my-square)
(check-expect (col 2 my-square) (above my-square my-square))
(define (col n img)
(cond
[(zero? n) (square 0 "solid" "black")] ; "null" image
[else (above img (col (sub1 n) img))]
))
; N Image -> Image
; Generates a new image that consists of n times img placed vertically
(check-expect (image-width (row 0 my-square)) 0)
(check-expect (row 1 my-square) my-square)
(check-expect (row 2 my-square) (beside my-square my-square))
(define (row n img)
(cond
[(zero? n) (square 0 "solid" "black")] ; "null" image
[else (beside img (row (sub1 n) img))]
))
(define (render img)
img)
(define (main img)
(big-bang
img
[to-draw render]
))
(define hall (row 10 (col 18 my-square)))
; List-of-balloons Image -> Image
; Adds a list of balloons to the passed image
(define (add-balloons lob img)
(cond
[(empty? lob) img]
[else
(place-image
balloon
(posn-x (first lob))
(posn-y (first lob))
(add-balloons (rest lob) img)
)]))
(main
(add-balloons
(cons
(make-posn 10 10)
(cons
(make-posn 30 70)
'()))
hall
))
(require test-engine/racket-tests)
(test)