CSc 101: Paint

In this assignment, you’ll be writing a program that allows the user to “paint” pictures on a canvas, much like the old Microsoft Paint program included with Windows. The user will be able to specify the color and size of the paint-brush to be drawn with keyboard buttons, and will specify where the circle is drawn via mouse coordinates and clicks. The user will also be able to “save” their drawing to a jpeg file with a button-click.

In it’s initial state when run, the program will be a blank white 700x400 canvas.

Wherever the user clicks and drags their mouse, the “paint-brush” with paint the appropriate color and brush-size. By default the brush will have a diameter of 90 pixels and will be red. For example:

The user can change the diameter of the brush to be drawn with the number keys. The number keys 1, 2, 3, 4, 5, 6, 7, 8, and 9 will change the diameter of the circle to 10, 20, 30, 40, 50, 60, 70, 80, and 90 pixels, respectively. Below is an example of each setting. In-between each drawn clicks, the associated number key is pressed.

The color of the brush to be draw can also be changed with the keyboard. If the ‘r’ key is pressed, the color is changed to red. If the ‘g’ key is pressed, the color is changed to green. If the ‘b’ key is pressed, the color is changed to blue. If the ‘y’ key is pressed, the color is changed to yellow. The color setting is saved and remains set until another color key is pressed. For example:

When the mouse is held down and dragged around and the sizes/colors are adjusted, you can draw pictures!

When the ‘c’ button is pressed, the painting canvas will be “cleared” to blank-white:

Lastly, when you press the ‘s’ button on the keyboard, your program will save the canvas as a jpg image in the same filder as the code file. The name of the image should be drawing.jpg. To save the current canvas to a file with this name, use this one special line of code: save("drawing.jpg");. In the below example, the ‘s’ key is pressed after drawing, and you can see the new image file created:

You should set the frameRate of the sketch to 30. You should call your program paint.pde.

Commenting

All of your programming should be well-formatted and easy for the graders to read and comprehend. Each program file should have a header comment at the top that has the following format:

//
// Author: Student Name
// Description:
//    A short description of what this program does!
// 

If any part of your scripts are particularly complex, you should put documentation comments above those lines of code.

Submission and grading

This was assigned on 10/6/2017. It is due on 10/20/2017 at 5:00pm. (You have two weeks instead of one, due to the exam).

Turn in each of the files described in the spec (just 1) the assignment 5 drop-box in D2L before the due date. Make sure to name the files exactly as this document specifies. In general, make sure to follow these instructions precisely. If you don’t, we will deduct points!!!