Design an interactive program StampSketch
that does the following:
- It creates a window of size at least 500 x 500.
- It should have a background that has a horizon line
separating two regions.
- For example, your background could have a blue sky
over green grass, or a blue sky over an ocean of
waves
- Some aspect of the background should be generated using
randomness and iteration (for or while loops).
- For example, you might draw a nighttime sky filled with
randomly colored and sized stars, a green field with
random blades of grass, or a tessellated background with
random colors.
- Your use of for or while loops can be as simple or as
complex as you wish. Your program must simply use one or
more loops to draw the background.
- Each time the user presses a key, the program should
erase whatever is displayed and redraw the random
background. The background should be different with
each subsequent keypress.
- As the user clicks on the sketch, it should draw an
object or character at that location. Something
about the physical size of this object or character must
change based on its location, relative to the horizon
line.
- The size should be smallest at the horizon line, and
should increase as the mouse moves farther away from
the horizon line.
- For example, the size of a house could increase as
the user clicks closer to the center of the sketch, or
a smiley face's eyes could enlarge and its mouth grin
depending on where it was placed.
- After several clicks, your sketch should have
multiple copies of the object at different locations
on the screen, each varying slightly based on the
mouse position.
- You cannot use Processing's built-in scale() command to scale the object. All scaling must be done manually using variables and mathematical computations.
- There must be one type of object or character in the top
region (e.g., the sky) and a different type of object or
character on the bottom region (e.g., the grass). For
example, your program could draw clouds in the sky and
tufts of grass on the ground.
- You could even draw multiple different types of
objects or characters in the sky that are randomly
chosen
- If you want to use colors other than the standard red, blue, black etc, we recommend you use this resource
Somewhere within your sketch, you must use (1) variables,
(2) conditional if or if-else statements, and (3) for or
while loop iteration.
Here are some ideas of the types of images that the final program
should be able to generate. Your objects can be simple or
extremely fancy.
To help you get started, here is a program template. As always, the TODOs are where we expect you to fill in your code. The remaining code can be used as is.
/**
* TODO - file header
*
*/
// TODO declare variables
void setup() {
// TODO set up the drawing
drawBackground(); // call the drawBackground() method
}
void draw() { /* remains empty */ }
void mousePressed() {
// TODO Use the mouseX, mouseY position to change the physical size of your object
// TODO Draw the object
}
void keyPressed() {
drawBackground(); // call the drawBackground() method
}
// clear the entire image and redraw the background
void drawBackground() {
// TODO draw a background that contains random elements and repetition using a for loop
}
- Generated background using randomness and for/while loop
iteration
- Pressing a key clears the sketch and redraws a new background
- On mousePressed, different types of objects are drawn on the
sketch at the mouse location
- The physical shape of the object (size, shape, etc.) changes
based on the mouse location
- Conditional if or if-else
tests are used somewhere in the assignment
- Variables used appropriately in the remainder of the
assignment
- Includes proper header and adequate comments
Restrictions:
- You cannot use Processing's built-in
scale()
command to scale the object. We will cover this command
about halfway through the semester when we talk about
transformations. All scaling must be done manually using
variables and mathematical computations.
- Make sure that it is at least 500 pixels by 500 pixels.
Your sketch should not be larger than 1000 x 1000 pixels.
- Your program must work perfectly if these values are changed
in the
size()
command. Therefore, you
should rely on the width
and height
variables throughout your program instead of hard-coded
values.
- Your objects or characters can be simple. For example,
clouds could be made of multiple ellipses, flowers could be made
with nested colored ellipses and a green rectangle.
- Your code should use variables as appropriate.
- Include proper source code header and adequate comments.
- We recommend the following steps to develop your
program. After each step, you should run and test your
program thoroughly, ensuring that it works.
- Begin by randomly generating the background. Develop
this slowly, building up complexity as you go. Test it
to make sure it works after every few lines of code.
- Add in the keyPressed() method that clears the
background. Test that it works.
- Add in the mousePressed() method to draw a simple shape
(e.g., a single ellipse) at the mouse location upon a
click. Test that you can draw multiple objects and
randomly regenerate the background.
- Scale size of the simple shape based on the distance from
the horizon.
- Change the simple shape to the more complex looking object
you want to draw. Test your code.
- Modify your complex object to adjust some aspect of its
appearance (i.e. shape or size) based on the mouse
location. Test your completed program.
- Do not try to write the entire program at once. Trying to do
everything at once and expecting it to work is the pathway to
frustration. Instead, build your program up slowly,
testing as you go to ensure that you always have a working
program (and if it doesn't work, the error was in the small bit
of code you just wrote).