CSci 1301: Lab 3

Friday, September 30. Due: Wednesday, October 5 at 11:59pm by e-mail

What to submit

The lab is done in groups of 2. In the beginning of each file please write (in comments) the names of all group members.

At the end of the lab please send me and your group partner(s) all your Racket files as e-mail attachments. My e-mail is elenam at morris.umn.edu. The subject of your e-mail must be "1301 Lab 3" followed by "Final" or "Not final", depending on whether this is a final submission or you are still working on it. If you need to finish it, make sure to set up a time with your group partner(s) to finish the lab.

The lab general description

The lab asks you to build upon examples of Racket "worlds". Racket "worlds" allow you to create programs similar to animations, but worlds are interactive, i.e. they can react to mouse movements, pressed keys, and the like. Functions for worlds are given in the universe.rkt teachpack.

Examples we have considered in class: moving dot, and recording positions of clicks

Task 1 (16 points): Improving the moving dot example

Start from the moving dot example that we did in class. Your tasks are as follows:

Task 2 (4 points): Changing the clicks example

Study the example of showing the position of clicks: recording positions of clicks. Change it so that it shows empty canvas before the first click (hint: what is the world state before the first click? Add a special case to show for it that just shows a blank scene).

Task 3 (8 points): Adding handling clicks to the dot example

Now we would like to be able to click on a spot on the canvas and make the dot jump to the place that was clicked.

Your click handling function should check that the type of event is "button-up" using a mouse=? function, and if it is, it should return the state of the dot as the the x and y cooridnates of the click. Don't forget to include the else part of the condition to leave the dot position unchanged.

As always, pay attention to code quality: use of functions, well-chosen names, function documentation, comments, etc.

Extra credit, 10 points: add key handling to change the color of the dot

Copy your current moving dot solution into a separate file: you will be making changes in multiple places.

The only way to keep track of the color of the dot is to incorporate it into the world state. This means expanding the structure that you currently have. You can do it in two different ways: use a nested structure that contains the posn structure and the color, or define your own structure that contains x, y, and a color. Discuss which of these approaches you would like to take and change the world state accordngly. This means changing all the current functions that consume the state (you don't have to copy over all the functionality that you have implemented earlier, just a couple of key events and the mouse event). Use the color part of the structure in show (instead of the current magenta) to display the color.

Test your changes carefully, use a color different from magenta when you provide the initial world state to the big bang.

Pick some letter keys to denote color, for instance "y" for yellow, "g" for green, etc. Make sure they are different from the keys that you use to move the dot. Add these cases to your key event handling functions to change the world state to the color determined by the key. If your show function uses the color in the world state then this should be sufficient to see the color changes. Test your world to see if all events are working as expected.


CSci 1301 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.