Learn creative coding writing simple programs

71. Playing with directions

One thing we discover this time is how to make an if() statement that tests more than one thing: do something if certain thing is true, OR if some other thing is true. The key here is the "or". In the current example, we want to check if our line has gone out of the screen through any of the four borders. This is translated into: if the line crossed the top border, or if the line crossed the left border, or the right border, or the bottom border, then jump back to the center of the screen. We are checking if at least one of those conditions is true. In many programming languages, Processing included, we type two vertical bars "||" when want to say OR. For example, if(i == 1 || i == 2) would test if the variable "i" is either 1 or 2.
In this episode we also play with the line width and color, and with the direction in which the line turns most of the time.

Tags: or, direction, angle, strokeweight, Lesson

Code editor

You can make changes to the code below. Then
Questions and comments are welcome! :) But please try to stay close to the topic of this episode. Use the Processing forums for help with your Processing projects (or hire me for help ;-)