Work in groups of 2 or 3.
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 (with the changes that we made in class), and recording positions of clicks.
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).
Start from the moving dot example that we did in class. Your tasks are as follows:
random
. Try changing the width
and height to see if it's always on the screen. 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.
Make sure that your file is named correctly:
Name your file with the combination of your last names, no spaces, followed by the word "Lab"
and the lab number.
For instance,
if your last names are Smith and Lee, the file name should be SmithLeeLab4.rkt
If there are others in the class with the same name as yours, you your initial in addition
to your last name: MSmithJLeeLab4.rkt
At least one person in the group must submit it via canvas as a file upload (make sure it's that .rkt
file).
Make a comment indicating who you worked with. The other person (or people) in the group may submit the same file and also
indicate who was in the group or just make a comment listing all your group members (note: if you don't submit a note listing
your group members,
your work may not be counted, even if your group partners list you as the group member).