Home‎ > ‎Unit 04‎ > ‎

Functions - Draw and Setup

Functions are portions of code within a program that does something specific. We've used some functions that are a part of the Processing language already. Functions have a name followed by parameters in parentesis. Like rect(100,100,50,50). The functions we've used so far work the same every time we use them, with the exception of how the parameters change them. In this unit we will be using functions that are specific to Processing, but you will program the behavior of.

Watch the video below and read Pages 51-52 in Getting Started with Processing.
What should you know?
  • Basic structure of Processing Sketch:
    1. Declare Variables
    2. void setup() - Runs once, typically includes functions that only need to run one time.
    3. void draw() - This function runs over and over again.
  • Variable Scope
    • Global variables are declared at the beginning of the sketch and can be used within any function
    • Local variables are declared inside of a function. Local variables only have meaning within a single function. So if a variable is declared within setup() you can not use it in draw().
  • How to use the print function
    • print() will print something in the console below the sketch
    • println () will print the parameter and then go on to the next line.
    • If the parameter is a variable the value of the variable will be printed
    • If text is put in quotes then the text will be printed. Text in quotes is referred to as a "String".