![]() |
![]() |
|
home—info—lectures—exams—hws—archive
Due in class Feb.091.
Turn in on WebCT.
In addition, if you're local, bring a hardcopy to class.
Over the course of a few homeworks, we'll develop a the fire-fighting-game, where a plane flies back and forth on the screen, trying to drop water onto fires which steadily grow bigger unless doused.
We design a program by identifying what types of data/objects the game needs, and then follow the design recipe for each one.
Water-droplets have two pieces of information: the x- and y- coordinate of their location.
(5pts) Write a function move-droplet : droplet → droplet which takes in a droplet, and returns another droplet whose location is slightly below the previous. (This is reminiscent of grow-boa from lecture.)
Include at least two test cases. By the way, in my solution, one of my test cases is (check-expect (fall-droplet drop1) drop2), since I'd previously “happened” to make my drop2 be just like drop1 but a bit lower.
Read the info below, about creating scenes.
(5pts) Write a function draw-droplet : droplet scene → scene which takes two inputs: a droplet and a scene, and returns a new scene with a blue-circle placed on it, representing the droplet.
Include (at least) one test case. My test case was:
(check-expect (draw-droplet drop2 (empty-scene 200 100)) (place-image (make-circle 10 'solid 'blue) 50 11 (empty-scene 200 100)) |
Fires have two pieces of information: their intensity, and their location. (Fires are always located at the bottom of the screen.)
(5pts) Write a function fire->image : fire → image, which takes in a fire and returns an image. (Just the individaul image -- not an image-drawn-onto-a-scene.) (You can use the three various-sized images from the game assignment, or your own images.
To get a gif/jpeg into DrScheme IDE, use Insert > Insert image…. You'll want to pass that image as one of the arguments to place-image.
Use if or cond to select which image to return, based on the fire's intensity.) Include at least three test-cases.
Recall from hw01, how we created images, and could even compose new images by using overlay or overlay/xy.
For this assignment, we'll use the same notion, but with one difference: We'll start with a scene, which is just an image except that when you put other images on top of it, they are clipped to the boundaries of the scene. Instead of overlay/xy, we'll use place-image (whose first input is any image, and the second input must be a scene).
(Here are docs for empty-scene and place-image.)
For example, you can evaluate the following expressions:
(empty-scene 200 100) (define my-painting (place-image (rectangle 20 30 'solid 'blue) 50 60 (empty-scene 200 100))) my-painting (place-image (circle 15 'solid 'orange) 190 40 my-painting) my-painting |
See also scheme-resources—ITEC380 Scheme resources.
The following problems will be on future homeworks, but are not due as part of this homework.
(check-expect (count-zeroes empty) 0) (check-expect (count-zeroes (cons 7 empty)) 0) (check-expect (count-zeroes (cons 0 empty)) 1) (check-expect (count-zeroes (cons 2 (cons 0 empty))) 1) ;;; PROVIDE TWO ADDITIONAL TEST CASES (using ‘cons’, not ‘list’) |
1If you need an extra 24hrs, it will be granted, but try to have it completed by Monday. ↩
2You are not being asked to make one plane object and then change its fields -- we're making three different plane structs which are all similar to each other. ↩
home—info—lectures—exams—hws—archive
©2009, Ian Barland, Radford University Last modified 2009.Feb.14 (Sat) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |