-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-4-4.rkt
58 lines (45 loc) · 1.64 KB
/
1-4-4.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
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname 1-4-4) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
(require 2htdp/image)
(require 2htdp/universe)
; A WorldState is a Number.
; interpretation number of pixels between the top and the UFO
(define WIDTH 300) ; distances in terms of pixels
(define HEIGHT 100)
(define CLOSE (/ HEIGHT 3))
(define MTSCN (empty-scene WIDTH HEIGHT))
(define UFO (overlay (circle 10 "solid" "green") (rectangle 30 5 "solid" "green")))
UFO
; WorldState -> WorldState
(define (main y0)
(big-bang y0
[on-tick nxt]
[to-draw render/status]))
; WorldState -> WorldState
; computes next location of UFO
(check-expect (nxt 11) 14)
(define (nxt y)
(+ y 3))
; WorldState -> Image
; places UFO at given height into the center of MTSCN
(check-expect (render 11) (place-image UFO (/ WIDTH 2) 11 MTSCN))
(define (render y)
(place-image UFO (/ WIDTH 2) y MTSCN))
; WorldState -> Image
; adds a status line to the scene created by render
(check-expect (render/status 10)
(place-image (text "descending" 11 "green")
20 20
(render 10)))
(define (render/status y)
(place-image
(cond
[(<= 0 y CLOSE)
(text "descending" 11 "green")]
[(and (< CLOSE y) (<= y HEIGHT))
(text "closing in" 11 "orange")]
[(> y HEIGHT)
(text "landed" 11 "red")])
20 20
(render y)))