ITP RESIDENTS

The Residents

Resources

Links

ICM Help Session Week 2: Variables, Conditionals, and Interaction

Mimi

What we covered in Week 2′s ICM Help Session:

Here’s the example we created together during the help session.

Variables

What are they useful for? Storing information your program needs to run, especially information that changes over time (e.g. location of a ball).

- Declaring variables : Telling your computer you want memory to store information. (To make variables “global”, declare them at the top of the sketch outside of setup and draw)
- Initializing (Setup) : What values do you want your variables to start with when you run your program?
- Running (Draw): How do you want your variable values to change over time?

Conditionals

I want one thing to happen if and only if something else happens.

- && and || (ands and ors)
- >,=,

Random

- I want my ball to bounce around randomly. I want my ball to change color randomly.
- Why do “randomly” generated things look so evenly spread out?

Creating Counters

I want something to happen, but only for 5 seconds.

Mouse/Keyboard Interaction

- Interrupts the draw loop to run code when you interact with your keyboard or mouse
- mousePressed(), keyPressed(), etc…

 

STATE SWITCHES

Here is an example of how to use a boolean, conditionals, and mousePressed to create a simple state switch- changing the color of a circle from one to another.

Click the mouse over the circle!