SetUp and Draw
- Processing used curly brackets to define code blocks (paragraphs).
- Code blocks with lables like setup and draw are called functions.
- There are two famous functions setup and draw that will be part of almost every processing program. Most of the lines of code you wrote were executing lable labled blocks of code, functions, that exist in the background. For example, somewhere behind the scenes in processing there is a function labled ellipse. Next week we will name our own functions.
- Disregard the void If you are having trouble disregarding the void... the name of the function is preceed by the type of thing it will give back (returns) after it runs, void if it gives back nothing. I told you to disregard the void!
- Where you put your code will determine When it will happen
- Happen once at the beginning of the program, put it in the setup code block. Handy for initialization
- Happen all the time. Put in the draw code block.
- Happen some of the time. Put in an IF code block within the draw code block.
- Give your program some ongoing life
- For now we will only be concerned one repeat loop, the "main" loop, which is created by with the draw function.
- Processing repeated calls the draw function for you thus creating a repeat loop.
- This loop starts after setup has been run once and will continue infinitely.
- Computational media is changeable thanks to variables.
- Variables are places in memory that you can set aside to store things. You might imaging in your mind a physical location like a coffee cup in the machine where you can put things. On the front of the coffee cup is the name you gave to your variable.
- The real power of variables is not just that you can store thing but that they can vary, thus the name.
- The hard work with variables is finding the most interesting things to make changeable in your program.
- It takes a while for the power of this concept to sink in. To start with you might just try turning fixed numbers into variables and see if you programs get more interesting.
- You put something in a variable by using a (single) equal sign.
- Processing is a "typed" language meaning you have to specify what type of thing you are storing in the variable. Often type is dependent on the size of the thing you are storing in the variable.
- You get some variable (aka properties) for free from Processing (eg.width, height, mouseX, mouseY, key )
- You can create a variable just by coming up with a name.
- The name can be anything that does not start with a number.
- Processing may try to read any word that is not reserved (colored gold) or in quotes as a variable.
- It makes your code much more readable (especially for the future) if you take some time and think what the variable is varying and then name it appropriately like speedOfMovement or direction_of_movement.
- Some people prefer to use lower case to start the variable and upper case for the beginning of each new word in the name. Other people prefer an underscore character between words. It is just a matter of style.
- Variables have different scopes, or lifespanes. Instance variables last for the life of your program and they should be mention at the very top of the program. Some variables need only to last for the life of a particular code block.