-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path01-3-rocket-examples.rkt
executable file
·36 lines (26 loc) · 1.3 KB
/
01-3-rocket-examples.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
;; 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 01-5-rocket-examples) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
;; making examples human-readable
;; a rocket simulation.
;; Information Analysis:
;; We have a single rocket, which is at some altitude and is
;; travelling vertically at some velocity.
;; We should be able to pause the animation
;; a Rocket
(define-struct rocket (altitude velocity))
;; A Rocket is a (make-rocket Real Real)
;; INTERPRETATION:
;; altitude is the rocket's height, in meters
;; velocity is the rocket's velocity, in meters/sec upward
;; rocket-after-dt : Rocket Real -> Rocket
;; GIVEN: a rocket and and a time interval
;; RETURNS: the state of the rocket after the interval has passed
;; EXAMPLE:
;; (rocket-after-dt (make-rocket 100 30) 0) = (make-rocket 100 30)
;; (rocket-after-dt (make-rocket 100 30) 2) = (make-rocket 160 30)
;; BETTER
(define rocket-at-100 (make-rocket 100 30))
(define rocket-at-160 (make-rocket 160 30))
;; (rocket-after-dt rocket-at-100 0) = rocket-at-100
;; (rocket-after-dt rocket-at-100 2) = rocket-at-160