Learn creative coding writing simple programs

20. The smallest drawing program ever

In this episode we learn how to read the current mouse position which is stored in the variables mouseX and mouseY. We also learn how to find out if the mouse button is clicked using the mousePressed variable. With this information we make a very simple drawing program.

Then we create a keyPressed() function to detect when the user presses a key on the keyboard. When the user presses a key, we call the save() function to save our drawing to an image file in our hard drive. You later can send the image by e-mail if you want.

Tags: beginners

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
  Do `float` and `int` smell similar?
To highlight code blocks, use ```processing and ``` like this:
  void setup() {
    size(600, 600);