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
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