These are my notes from the book How to Design Programs available online here, using Racket and the Beginner Student Language (BSL) which is lot like the Scheme dialect of LISP. Look at Part 1 here.
Prologue Part 2
Most of the code is commented out so I can run the latest written code only.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 |
(require 2htdp/image) (require 2htdp/universe) ;(define (y x) (* x x )) (y 1) (y 2) (y 3) (y 4) (y 5) (y 6) (y 7) (y 8) (y 9) (y 10) (empty-scene 100 60) (place-image . 50 23 (empty-scene 100 60)) (define (picture-of-rocket height) (place-image . 50 height (empty-scene 100 50))) (picture-of-rocket 0) (picture-of-rocket 10) (picture-of-rocket 20) (picture-of-rocket 30) (animate picture-of-rocket) (define (sign x) (cond [(> x 0) 1] [(= x 0) 0] [(< x 0) -1])) (sign -5) (define (picture-of-rocket.v2 height) (cond [(<= height 60) (place-image . 50 height (empty-scene 100 60))] [(> height 60) (place-image .50 60 (empty-scene 100 60))])) (animate picture-of-rocket.v2) (define (picture-of-rocket.v3 height) (cond [(<= height (- 60 (/ (image-height .) 2))) (place-image . 50 height (empty-scene 100 60))] [(> height (- 60 (/ (image-height .) 2))) (place-image . 50 (- 60 (/(image-height .) 2)) (empty-scene 100 60))])) (animate picture-of-rocket.v3) (define (picture-of-rocket.v4 h) (cond [(<= h (- HEIGHT (/ (image-height ROCKET) 2))) (place-image ROCKET 50 h (empty-scene WIDTH HEIGHT))] [(> h (- HEIGHT (/ (image-height ROCKET) 2))) (place-image ROCKET 50 (- HEIGHT (/(image-height ROCKET) 2)) (empty-scene WIDTH HEIGHT))])) ; properties of the "world" and the decending rocket (define WIDTH 100) (define HEIGHT 60) (define V 2) (define X 50) ;constants (define MTSCN (empty-scene WIDTH HEIGHT)) (define ROCKET .) (define ROCKET-CENTER-TO-TOP (- HEIGHT (/ (image-height ROCKET) 2))) ;functions ;(define (picture-of-rocket.v5 h) ; (cond ; [(<= h ROCKET-CENTER-TO-TOP) ; (place-image ROCKET 50 h MTSCN )] ; [(> h ROCKET-CENTER-TO-TOP) ; (place-image ROCKET 50 ROCKET-CENTER-TO-TOP MTSCN)])) (define (picture-of-rocket.v6 t) (cond [(<= (distance t) ROCKET-CENTER-TO-TOP) (place-image ROCKET 50 (distance t) MTSCN )] [(> (distance t) ROCKET-CENTER-TO-TOP) (place-image ROCKET 50 ROCKET-CENTER-TO-TOP MTSCN)])) (define (distance t) (* V t)) (animate picture-of-rocket.v6) |
Reader Comments