;; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS FILE. ;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU AND, IF YOU HAVE ONE, YOUR ;; PARTNER. (require 2htdp/universe) (require 2htdp/image) (require spd/tags)
(@assignment pset-04);Do not edit or remove this tag (@cwl ??? ???) ;;
;Replace ??? with your cwl,
;second ??? is replaced with partner cwl if you have one
(@problem 1) ;; Design a data definition for a song. Each song has a name, an artist, ;; and a duration (the length of the song in seconds). ;; ;; Your design must follow all applicable recipes, and must include all ;; appropriate @tags. Solutions which "just work" but do not follow the design ;; recipes will receive few if any marks.
(@htdd Song) (define-struct song (name artist duration)) ;; Song is (make-song String String Natural) ;; interp. a song with a title (name), artist, ;;
and length of time in seconds
(define S1 (make-song "Shape of You" "Ed Sheeran" 233)) (define S2 (make-song "Rockstar" "Post Malone" 218)) (define S3 (make-song "All of Me" "John Legend" 269))
(@dd-template-rules compound)
(define (fn-for-song s) (... (song-name s) (song-artist s) (song-duration s)))
(@problem 2) ;; Use your data definition from Problem 1 to complete this problem. ;; ;; Design a data definition for an arbitrary number of songs. ;; ;; Your design must follow all applicable recipes, and must include all ;; appropriate @tags. Solutions which "just work" but do not follow the design ;; recipes will receive few if any marks.
(@htdd ListOfSong) ;; ListOfSong is one-of: ;; - empty ;; - (cons Song ListOfSong) ;; interp. a list of songs (define LOS0 empty) (define LOS1 (cons S1 (cons S2 (cons S3 empty))))
(@dd-template-rules one-of atomic-distinct compound ref self-ref)
(define (fn-for-los los) (cond [(empty? los) (...)] [else (... (fn-for-song (first los)) (fn-for-los (rest los)))]))
(@problem 3) ;; ;; In this problem set, you will design a program that will simulate what ;; it might look like to zoom through outer space at a very high speed. ;; ;; If you were to look out the front window of a spaceship, you would likely ;; see a lot of black outer space. You also see stars appear in front of you, ;; and assuming the space ship is moving REALLY fast, you would see them zoom ;; by the side of the spaceship as you fly by. ;; ;; When a user clicks down with the mouse, a light will appear on the screen, ;; which represents a star in the distance. The light should appear at the ;; x and y coordinate on the screen where the mouse is when the user clicks. ;; The light should then begin to move toward the closest edge of the screen, ;; with its speed increasing every tick. ;; ;; If the light is in the top half of screen, it should move toward the top of ;; the screen, otherwise, it should move toward the bottom. Similarly, if the ;; light is in the left half of the screen, it should move toward the left edge ;; of the screen, otherwise it should move toward the right edge. One way to ;; think of this is to split the screen into four quadrants: top-left, ;; top-right, bottom-left, and bottom-right. If a light is in the top-left ;; quadrant it should move up and left toward the nearest corner.
;; ;; For this problem set, if light is exactly in the center of the vertical (y) ;; axis, the light travels up, and if a light is in the center of the horizontal ;; (x) axis then the light travels left. This means that a light placed in the ;; exact middle of the screen will begin traveling up and left. ;; ;; When a light is created, its initial speed is set to 0. Every time update-lol ;; is called the speeds of the lights are increased by SPEED-INCREASE amount. ;; ;; Your helper for update-lol MUST be called update-light. ;; ;; We have begun the design with constants (including a LIGHT-IMG constant ;; to be used when rendering a light onto MTS), data definitions, and a big-bang ;; function, all of which you MUST use and CANNOT change in your solution. ;; We have not provided wish list entries for the helpers nor have we provided ;; the helper definitions themselves. ;; ;; Your design must follow all applicable recipes, and must include all ;; appropriate @tags. Solutions which "just work" but do not follow the design ;; recipes will receive few if any marks. ;; ;; Cruising through Space! (@htdw ListOfLight)
;;=========== ;; Constants:
(define HEIGHT 400) (define WIDTH 600)
(define CTR-X (/ WIDTH 2)) (define CTR-Y (/ HEIGHT 2))
(define MTS (empty-scene WIDTH HEIGHT "black")) (define LIGHT-IMG (star 4 200 "white")) (define SPEED-INCREASE 1)
(define NUM-TO-ADD 50)
;;================== ;; Data Definitions:
(@htdd Light) (define-struct light (x y speed)) ;; Light is (make-light Integer Integer Integer) ;; interp. shooting star of a light with ;;
x and y screen space coordinates
;;
and the speed it is currently moving
(define L0 (make-light 1 2 3)) (define L1 (make-light CTR-X CTR-Y 1))
(@dd-template-rules compound)
(define (fn-for-light l) (... (light-x l) (light-y l) (light-speed l)))