Learn creative coding writing simple programs

21. Improved tiny drawing program

We continue with our tiny drawing program. The first version saved the image when you pressed any key on the keyboard. Now we check which key was pressed by reading the *key* variable. If we pressed *s*, we save the image. If the *b* key was pressed, we change the background color. And the *c* key changes the line color.
The background color is easy to see, but we don't know about the line color until we draw something. It would be nice to know about our line color *before* drawing anything. To solve this, we draw a thin line on the top border of our drawing which lets us see the current color.

Finally, we show how creating a function can avoid having repeated lines of code. We create a function that draws a line on the top border of the screen, and we call this function in two cases: after setting the background color, and after setting the line (stroke) color.

Tags:

Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus