Conditionals

Often we want to make our code interactive.  In order to do so, we will use an if statement.  Let's look at a quick example:

Example #1:  
Drawing a rectangle when the mouse is pressed

if(mousePressed)
{
   rect(250, 200, 50, 40);

}


Example #2:  
Drawing a rectangle when the mouse is pressed, and a ellipse when it isn't.

if(mousePressed)
{
   rect(50, 200, 50, 40);
}
else 
{
   ellipse(50, 200, 50, 40);
}



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.