CSci 1301: Lab 3

Due: Friday, September 27th at 11:59pm by e-mail

What to submit

The lab is done in groups of 2 (preferred) or 3. In the beginning of each file please write (in comments) the names fo 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.

In the beginning of the lab we will go over a few examples of creating worlds: An example of creating a "world" (recording mouse movements), from the book, handling key pressing events, handling different mouse events, including mouse clicks.

How to run a world program:

  1. Click run (or press Ctrl-R) to run the program. This loads your program. Note: make sure to re-run (i.e. re-load) after every change!
  2. In the interactions area (the bottom part) type (main 10) (10 is the number of seconds you want to run your program for; change this number as needed), press enter.

Lab task 1: expanding the key example (15 points)

This part of the lab is based on the keys.rkt. You need to expand the example as follows:

  1. Write the function random-square according to its description in the Racket file and then use it in the function handle-key.
  2. Fix an issue with squares placed over the frame sometimes (adjust the call to the random number generator). Note that you need to adjust both the range of the random numbers (i.e. what gets passed to a random number generator) and its lower limit. For instance, (+ 5 (random 10)) returns a random number between 5 and 14 (inclusive).
  3. Add two more cases to handle-key for two more different colors.
  4. Add handling for three more letter keys to add objects other than squares (such as circles, text, images). You might want to write helper function for these as well.

Test your porgram well after each addition. Note that you cannot use check-expect for testing since the program uses randomness, and therefore produces different results every time.

Lab task 2: clicking on squares (15 points)

This part of the lab is similar to the mouse-events.rkt. You need to write a separate program (in a new file) that displays a square divided into four quadrants of different color. The quadrants are shown as an outline. When the user clicks (i.e. presses the mouse button) on one of the quadrants, that quadrant becomes of solid color. All other quadrants becomes outlined, in their respective color.

Here is what the canvas look like after the user clicks the top left quadrant:

4 squares

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


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.