211 S '05 Assignments Set 1 Set 2 Set 3 Set 4 Set 5 Set 6 Set 7 Set 8 Set 9 Set 10 Set 11 Set 12 Set 13 Set 14

### Problem Set 2

Due date: 1/18 @ 4:30 pm

For this problem set, you will use the design recipe to systematically create simple functions and programs. The functions consume atomic forms of data (numbers, symbols, images) and also use conditionals to distinguish among various situations.

Optional: You may wish to explore the world.ss teachpack, which provides functions for composing and animating images. We strongly recommend that you at least make an attempt to solve these optional parts.

HtDP Problems:

2.2.4, 2.3.3, 5.1.5

Your buddies and you have decided to develop a piece of a game based on "Star Thaler", a fairy tale by the brothers Grimm. In this fairy tale, stars begin to drop from the skies and the main character, a poor girl, collects the falling stars ("thalers", "talers", "dollars") in her skirt.

A star thaler drops at the rate of five pixels per time unit. It starts at a height of 10; its visual appearance is that of a red disk.

Make up a table that shows how far a star thaler has dropped at times t = 0, 1, 2, 3 and 4. Remember that "down" means the numbers get bigger on a computer canvas.

Formulate a formula for the height of the star thaler, depending on the time. Test it on the numbers in the table.

Translate the formula into a Scheme function. Call the function `star-height`. Translate the table into tests.

Optional: Define the function `place-star`, which consumes a time (number of seconds) and produces a 100 x 100 scene with the star at the appropriate place. The star is always 20 pixels from the left.

Your manager asked you to develop a piece of a "space wars" game. One of the elements of the game is a UFO that descends from the top of the canvas to the bottom. When it reaches the bottom, it stops and just sits there. [Okay, in a real game, there are ways to shoot and destroy the UFO but we're not there yet.]

Design the function `ufo-height`. It consumes the time (in number of seconds) and computes the y-coordinate of the UFO. Assume that the UFO drops at a rate of 4 pixels per second until it is close enough to the ground; at that point it just lands. For us, "landing" means that the UFO no longer moves; "close" means that the UFO is within 2 pixels of the ground line. The height of the canvas is 200 pixels. The UFO is initially 5 pixels down from the top.

Optional: Define the function `place-ufo`, which consumes a time (number of seconds) and produces a 100 x 200 scene with the UFO at the appropriate place. The UFO is always 30 pixels from the left. Represent a UFO as yellow flying saucer (flat rectangle plus disk).

Design `worm-move`. The function consumes a keystroke, which is either a character or a symbol, and the head of a worm, which we represent as a `Posn`. It outputs a new `Posn`, representing the head's next position. If the keystroke is one of the four arrow keys (represented as the symbols `'up`, `'down`, `'left`, `'right`), the worm moves in the specified direction by 10 pixels. Otherwise, it remains on the spot. The worm also remains on the given spot, if a move were to bring it outside a 100 x 100 box.