Conditional Logic Part 2: Defining Spaces

e.g., mouse, keyboard
e.g., visualization, fractal, mouse
Learn more about Creative Commons
Join Plus+ to change privacy settings
  • Code Lesson:

    https://vimeo.com/459094168


    Explanation

    Defining Spaces

    In your projects, you may need to define very specific parameters with your conditional statements. A program may have several animations, boundaries, and/or responsive actions running simultaneously. In order to make sure programming events are all uniquely defined, we often need to conjoin several expressions inside of one condition.

    As you test the program, you will notice that whenever mouseX is past 25, the face displays. That is pretty handy but what if we want even more specificity for our rollover face? What about the face displaying whenever our mouse is within any side of the blue rectangle? To write a conditional that can specify all of these areas, we will need to use logical operators to conjoin multiple expressions.


    NEXT PAGE -->



  • Code Lesson Continued:

    https://vimeo.com/459094286



    The logical operator, “or”  (expressed with double pipes: | | ) conjoins two alternate conditions. If either side of the | | operator is true then the code will be executed. The logical operator “and” (expressed with double ampersands: &&) combines conditions. All conditions conjoined by the && operator must be true before the code will be executed.  The “not” operator (expressed with an exclamation point: !) is used to negate an expression. We will use this in future lessons.

    In summary, logical operators combine simple relational statements into more complex expressions. It is important to note that parentheses enclose each individual condition and the entire conjoined condition for the sake of clarity. 


    Next Page -->

  • Code Lesson Continued:

    https://vimeo.com/459094269


    Why doesn't this work?

    Keep an eye out for logical errors when conjoining conditions. In this example, the condition will never be true because it is logically impossible.


1/3
  • mySketch
Select mode or a template
Centers sketch and matches the background color.
Prevents infinite loops that may freeze the sketch.
This will be the default layout for your sketches
Easy on the eyes
It will show up when there is an error or print() in code
Potential warnings will be displayed as you type
Closes parenthesis-like characters automatically as you type

Controls
Play
Ctrl+Enter
Code
Ctrl+Shift+Enter
Save
Ctrl+S
Interface
Fullscreen
Ctrl+Alt+F
Switch Layout
Ctrl+Alt+L
Settings
Ctrl+Alt+.
Editor
Tidy Code
Ctrl+B
Multiple Cursors
Ctrl+Click
Duplicate Line/Selection
Ctrl+Shift+D
Move Line
Alt+↑/↓
Select Multiple
Ctrl+D
Find in Code
Ctrl+F
Find Next
Ctrl+G
Find Previous
Ctrl+Shift+G

See More Shortcuts

Join Plus+ for private sketches, version history, 1GB space, custom embeds, and more!