Guest User

Untitled

a guest
May 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.07 KB | None | 0 0
  1. ; Jake Ascher & Nick Tinsley
  2. ; Assignment 1
  3.  
  4. ; Problem 1
  5.  
  6. ; A City is a (make-city zip name state long/lat)
  7. ; Where zip is a 5-digit symbol
  8. ; name is a symbol
  9. ; state is a 2-character symbol
  10. ; and long/lat is a Posn
  11.  
  12. ; A Posn is a (make-posn x y)
  13. ; Where x and y are numbers
  14.  
  15. (define-struct city (zip name state long/lat))
  16. (define boston (make-city '02115 'Boston 'MA (make-posn 71.0922215 42.342706)))
  17. (define hartford (make-city '06120 'Hartford 'CT (make-posn 72.675807 41.78596)))
  18. (define augusta (make-city '04330 'Augusta 'ME (make-posn 69.766548 44.323228)))
  19. (define concord (make-city '03301 'Concord 'NH (make-posn 71.527734 43.218525)))
  20. (define montpelier (make-city '05602 'Montpelier 'VT (make-posn 72.576992 44.264082)))
  21. (define providence (make-city '02908 'Providence 'RI (make-posn 71.437684 41.838294)))
  22.  
  23.  
  24. ; Problem 2
  25.  
  26. (require 2htdp/image)
  27.  
  28. (define left-map 125)
  29. (define right-map 65)
  30. (define top-map 50)
  31. (define bottom-map 20)
  32.  
  33. ; to-posn : City -> Image
  34. ; Consumes a city and places the city onto a scene at the correct position.
  35. (define (to-posn city)
  36.   (place-image (circle 2 "solid" "red")
  37.                (- 100 (* (/ (- (posn-x (city-long/lat city)) (- left-map right-map))
  38.                      (- left-map right-map))
  39.                   100))
  40.                (- 100 (* (/ (- (posn-y (city-long/lat city)) (- top-map bottom-map))
  41.                      (- top-map bottom-map))
  42.                   100))
  43.                (empty-scene 100 100)))
  44.  
  45.  
  46. ; Problem 3
  47.  
  48. ; to-posn-par : City Number Number -> Image
  49. ; Consumes a city, width, and height of a canvas and places the city onto a scene at the correct position.
  50. (define (to-posn-par city width height)
  51.   (place-image (circle 2 "solid" "red")
  52.                (- width (* (/ (- (posn-x (city-long/lat city)) (- left-map right-map))
  53.                      (- left-map right-map))
  54.                   width))
  55.                (- height (* (/ (- (posn-y (city-long/lat city)) (- top-map bottom-map))
  56.                      (- top-map bottom-map))
  57.                   height))
  58.                (empty-scene width height)))
Add Comment
Please, Sign In to add comment