Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Jake Ascher & Nick Tinsley
- ; Assignment 1
- ; Problem 1
- ; A City is a (make-city zip name state long/lat)
- ; Where zip is a 5-digit symbol
- ; name is a symbol
- ; state is a 2-character symbol
- ; and long/lat is a Posn
- ; A Posn is a (make-posn x y)
- ; Where x and y are numbers
- (define-struct city (zip name state long/lat))
- (define boston (make-city '02115 'Boston 'MA (make-posn 71.0922215 42.342706)))
- (define hartford (make-city '06120 'Hartford 'CT (make-posn 72.675807 41.78596)))
- (define augusta (make-city '04330 'Augusta 'ME (make-posn 69.766548 44.323228)))
- (define concord (make-city '03301 'Concord 'NH (make-posn 71.527734 43.218525)))
- (define montpelier (make-city '05602 'Montpelier 'VT (make-posn 72.576992 44.264082)))
- (define providence (make-city '02908 'Providence 'RI (make-posn 71.437684 41.838294)))
- ; Problem 2
- (require 2htdp/image)
- (define left-map 125)
- (define right-map 65)
- (define top-map 50)
- (define bottom-map 20)
- ; to-posn : City -> Image
- ; Consumes a city and places the city onto a scene at the correct position.
- (define (to-posn city)
- (place-image (circle 2 "solid" "red")
- (- 100 (* (/ (- (posn-x (city-long/lat city)) (- left-map right-map))
- (- left-map right-map))
- 100))
- (- 100 (* (/ (- (posn-y (city-long/lat city)) (- top-map bottom-map))
- (- top-map bottom-map))
- 100))
- (empty-scene 100 100)))
- ; Problem 3
- ; to-posn-par : City Number Number -> Image
- ; Consumes a city, width, and height of a canvas and places the city onto a scene at the correct position.
- (define (to-posn-par city width height)
- (place-image (circle 2 "solid" "red")
- (- width (* (/ (- (posn-x (city-long/lat city)) (- left-map right-map))
- (- left-map right-map))
- width))
- (- height (* (/ (- (posn-y (city-long/lat city)) (- top-map bottom-map))
- (- top-map bottom-map))
- height))
- (empty-scene width height)))
Add Comment
Please, Sign In to add comment