Practice 2.5: Rainbow Painter
Make a program that allows the user to draw colored shapes

REQUIREMENTS

  • The user left clicks to draw randomly colored shapes

  • The user right clicks to erase shapes

  • The user middle clicks to clear the screen

  • Press '1', '2', and '3' to change the brush size to small, medium, and large brushes

STEP BY STEP

Part A - Starting Code

    • You'll want to run this program in full screen mode.

    • Note that in this project we need to set the background in setup() because we don't want to reset it every frame.

Starting Outline

void setup()

{

fullScreen();

// Set your background here

}


void draw()

{

// Empty for now

}

Part B - Painting


    • At the top of your program, make three float variables named red, green, and blue.

    • Create a method called paint()

      • Set each of red, green, and blue to random values between 0 and 255.

      • Set your fill color using red, green, and blue as values.

      • Draw a circle at the mouse's position.

    • In your draw method...

      • If the left mouse button is pressed, call the paint() method

Part C - Erasing


    • Create a method called erase()

      • Set your fill color to match your background color

      • Draw a circle at the mouse's position.

    • In your draw method...

      • If the right mouse button is pressed, call the erase() method

Part D - Clear


    • Create a method called clear()

      • Wipe the screen by set the background to your chosen color

    • In your draw method...

      • If the middle mouse button is pressed, call the erase() method

Part E - Brush Size


    • At the top of your program, create a float named brushSize.


    • In draw()

      • If the '1' key is pressed, set the brush size to a small number

      • If the '2' key is pressed, set the brush size to a medium number

      • If the '3' key is pressed, set the brush size to a large number

      • Hint: Don't forget the single quotes around the number.

    • In paint() and erase()

      • Replace your hardcoded width and height values with brushSize

Part F - Random Background (Optional)

  • Modify your program so that it sets a random background color at the start and each time the user middle clicks.

  • This seems easy - but you need to make sure the eraser tool still works properly

    • Hint: You will need to store these color values

  • Your screen cannot change colors every frame; only when the user has the right button pressed.

EXAMPLE: RUNNING PROGRAM