Problem Set 2
Purpose The purpose of this problem set is to practice developing simple and conditional functions. Most of the functions deal with atomic forms of data (numbers, symbols, strings, images). The last two problems are harder, and deal with compound data (structs).
Finger Exercises HtDP/2e: 13, 18, 19, 20, 21; 30, 31; 61, 64
Problem 1 Design the function favorite-star. Given two numbers (which represent the radius of a large circle and the radius of a small circle), and the color of the star, it places an appropriately sized and colored radial-star in the middle of a circle with the larger radius. If you are confused about how to make a radial-star of the appropriate size, you may want to take a look at the documentation.
Problem 2 Design a big-bang program which shows an alot moving through the jungle. If you don’t know what an alot looks like, you can go here to find out. The state of your world should be the leftmost point of the alot. When the alot reaches the edge of the screen, it should start again on the other side. There should be at least one tree behind the alot and some grass in front of him.
For an example of a similar animation, see problems 41-44 in HtDP/2e.
Note: The goal of this problem is not to test your skills as an artist. You will not be marked off if your alot/jungle does not look particularly realistic.
Problem 3 Before noon people usually greet each other with "good morning." From noon until 5 pm they usually just say "hello" because "good day" sounds like you are really done talking to people. After 5 pm and up until midnight people say "good evening". After midnight all they say is "zzzz" until 6 am the next morning.
Design a function that takes in the hour (on a 24 hour clock) and translates it into the greeting you should use.
a blue dot
a red dot
a black line between the blue and the red dots
a green dot frac of the distance from the blue to the red dot
Here is a sample output, where frac is 60%:
Domain Knowledge (Geometry) To find the next point for the green dot,
find the distance between the red and blue dot in each dimension and compute
the appropriate fraction of each. Combine the results with the respective
coordinates of the blue point—
Problem 5 Design a big-bang program that animates your answer to the previous problem. Start the green dot at the same position as the blue dot, and as time goes on the green dot should move closer to the red dot. It should take 200 ticks for the green dot to reach the red dot. What information will you need as your World? You should be able to reuse the main function you wrote above, but not directly: it takes two Posns and a Number, while the to-draw function in big-bang takes a World, so you’ll need to design one more function to extract the information from the World and call the drawing function above.
Problem 6 Daenerys is raising three dragons. Every time she feeds the dragons, they grow. Design a program that allows Daenerys to feed her dragons. Each dragon will show up as a different colored box, placed at the bottom of the screen. The height of the box will be determined by how much food the dragon has received. The user can feed a dragon by clicking on that box. The boxes should start at height 5 (because even baby dragons are at least 5 pixels tall). Feeding one dragon ONLY affects the height of that dragon. No dragon’s height should exceed the height of the screen.
Hint: the subtlest part of this problem is properly handling the mouse clicks. Make sure your code is designed well enough to convince readers that mouse clicking works...without having to play the game for themselves!
Don’t forget to follow the design recipe for programs!!! Ask a tutor or TA if you need help.