System, Environment
- What is Processing?
Processing is a programming language created by two programmers that caters more to artistic audience or any audience that hasn’t been exposed to coding before.
- What does IDE stand for? Describe its components.
IDE stands for integrated development environment. My understanding is that before you had to download each part of the IDE separately but the IDE conveniently has a debugger (which points out errors in code), an editor (the place where you write your code) and compiler (which transforms your code into “machine speak” so your computer can understand it) all in one.
- What is a mode in Processing? Which is the default mode?
My understanding is that Processing can be built on other languages so the program you create can work on different platforms. If you look at the top right of your Processing console you’ll see the default mode is Java, but you can also download other modes.
- How do you save a file in Processing? What convention might you use?
If you’re on a Mac you can type shift, command and S to “save as”. Some conventions include: never start the title with a number because the sketchbook won’t be able to find. Use camel case which means you write the first word of the title in lowercase and the first letter of the other words in uppercase, kindaLikeThis.
- How do you export a Processing file?
You would go to File and go down to “export application”. On a Mac you can do shift, command and E to go directly.
- What is a library? How do you access and use a library in Processing?
- Where is the color picker in the Processing IDE?
You click on Tools and click on color selector.
- What do the circle, triangle and square shapes across the top of the Processing editor represent?
I guess by circle you mean the button with the weird butterfly on it, that goes line by line of your code to find any “bugs” or errors. The triangle is to run the editor, so it goes line by line and the square is to stop that process.
- How do you add and name an additional or new tab in the Processing editor?
When you open your editor under the triangle and square button is the title of the sketch, usually just sketch and the date if it’s a brand new sketch. Next to it is a triangle pointing down, click on it and select “new tab” for a new tab and there you can add a name.
- Describe the coordinate system in Processing.
The coordinate system in Processing is similar to the Cartesian coordinate system we learned in high school geometry with an X and Y axis except point (0,0) doesn’t start at the bottom left corner but at the top left. Also I believe technically there are no “negatives” the negative sign just means you’re going back left a coordinate in Processing.
- What is the difference between an active and static sketch? Use code to demonstrate your response
A static sketch is one that isn’t interactive and doesn’t move like this:
fill(255, 35, 125);
ellipse(250, 175, 50, 50);
It doesn’t include setup() or draw()
An active sketch is one that incorporates setup() or draw() and i usually interactive and moves.
void setup() {
size(300,300);
}
void draw() {
fill(255, 35, 125);
ellipse(250, 175, 50, 50);
}
- What is the general syntax and structure for a line of code? Use code to demonstrate your response.
The general syntax for a line is usually a data type, a function and variables. The spacing should be consistent and make sure to add a semicolon and don’t forget parenthesis and curly brackets where needed. Here’s an example:
Void draw() {
- What is the general syntax and structure for a block of code? Use code to demonstrate your response.
General syntax is the same for the line of code. Also it’s good to indent the code that goes inside the function like this.
void setup();
size(300,300);
background(0);
Why are certain words in different colors in the Processing editor?
Words that turn into different colors like the word void or height means a specific function that is built into Processing is assigned to that word.
- What is a system or reserved word in Processing? Give an example.
I reserved word is a word that you cannot used because it’s assigned already to a function in the Processing language for example the word size. Size() tells you how big the canvas is going to be.
- How does order matter in Processing. Give an example demonstrated with code.
Order matters because when you execute the code, it goes line by line from top to bottom. So code that is above another line of code will influence it differently if it were on the bottom. For example:
fill(2500,50,50);
ellipse(22, 45, 20, 20);
rect(75, 36, 15, 15);
Makes both shapes red but
ellipse(22, 45, 20, 20);
fill(2500,50,50);
rect(75, 36, 15, 15);
Makes only the square red.
- What is the difference between mousePressed and mousePressed()? Use code to demonstrate your response.
- What called function must always be first in setup()?
After Setup() is typed the next line should be size() which determines the canvas size. You need to know the size before you can start drawing. Also the function void should also be included before setup() so the program knows it doesn’t have to return anything.
- What is the difference between an inline comment and a block or multi-line comment? Use code to demonstrate your response.
An inline comment is one where just a line is a comment and the program doesn’t read it. A multi-line comment is more than one line of comment.
//This is an inline comment
/* This right here that I am typing
on this website right now is multi
line comment */
- Does whitespace matter in Processing? Capitalization? Use code to demonstrate your response
Whitespace and capitalization matters in Processing because it changes how the editor reads a line of code. For example if you type Void setup() the editor will not recognize it and you’ll get an error but if you type void setup() the word void will turn green because that refers to the function already built into processing. Also let’s say you assign the number 100 to a word like “birthday” if later you want to call that variable you won’t get the number 100 if you type Birthday, with a capital letter.
Variables, Operators, Logic
- What is a variable? What is a data type? What is a value?
My understanding is that a value is the representation of some entity that can be manipulated by a program. So the 1s and 0s that make the data.This is what the computer understands. A variable is something that temporarily stores a value so you the user can better understand, For example myBirthday = 22, myBirthday is a variable that for at the moment holds the number 22. In processing there are different information you can give to variables so this has to be stated with the right data type or type of data. Int is for whole numbers, boolean is for true or false, float is for decimal numbers, etc.
- What is the difference between a system variable and one that you define? Use code to demonstrate your response.
Like the name suggests a system variable is one where a value is already been assigned to it and is part of the Processing program. I believe you can technically change it but it’s a little more difficult. The variable you define is one you assign a value to and can be changed easily. For example width, is a system variable, it stores the width of the display window. If you type it in Processing the program will understand what you mean. The variable xCo for the x coordinate will in turn be read as error because you haven’t defined it. So you would have to type something like int xCo = 20 for the program to understand, but YOU are the one picking the value as oppose to the value already been defined before
- What is scope and how does it impact code? Use code to demonstrate your response.
There are two types of scopes relating to variables. There’s “global” and “local”. If you have a function and within that function you declare a variable, that is a local variable, the program will only understand it when is within that function, if you use a local variable outside the function it’ll come back as error. A global variable is declared outside all functions so all other functions have “global” access to it.
float rCol = 255;
float gCol = 255;
float bCol = 255;
float speed = 1;
float offset = 125;
//speed, rCol and every word after float is a global variable here
void setup() {
int R = 160;
int G = 50;
int B = 80;
//int R,G,B are local variables because they’re inside the void setup() function
size(600, 400);
background(R,G,B);
}
- What does it mean to declare, initialize and use a variable? Use code to demonstrate your response.
Declaring a variable means to assign the right data type (for example float, int, boolean etc). Initialize means to give the variable a value. Using means you use the variable to call the value that is assigned to it, in a line of code.
For example int red is declaring variable. int red = 200 is initialization. background(red, blue, green); is calling or using the variable, in this case the variable red.
- What happens when a variable is attempted to be accessed outside of its scope?
- What happens when a variable is declared globally, but is not used?
The variable will be there but it won’t be used it’ll just be floating there.
- What value does float nums; have?
- What are operators in Processing? Use code to demonstrate your response using at least one operator.
- What is a boolean data type?
boolean is a data type (like char, float, int) for boolean statements so if something is true or false.
- List three primitive data types.
boolean, char and float
- Write a code example that increments a value by 5.
- Describe the order of operations for: x = speed * 40;
- Write a code example that decreases a value by one using shorthand.
- What does the logical operator ! do?
The exclamation mark is the logical not used in boolean. So if something is false it makes it true and if something is true it makes it false.
Control, Iteration, Structure
- What is an if statement? When should it be used? Use code to describe its syntax.
An if statement is a line of code that helps the program make a decision on which code to execute. For example if something is true it executes one line if something is false nothing will happen . It’s best used when you want more than one result . This allows the program to have different paths. An example is
void setup() {
size(600, 400);
background(255);
}
void draw() {
if (mousePressed) {
background(200, 50, 50);
}
}
- How many ifs can be used in an if statement?
You can have unlimited if statements. You can write a line with an if statement and underneath write another one.
- What is the difference between else and else if? Use code to demonstrate your response.
- What is the difference between code with several consecutive if statements and code with several else if statements?
- What is a while loop? When should it be used? Use code to describe its syntax.
- What is a for loop? When should it be used? Use code to describe its syntax.
- Write code that uses a nested for loop to draw a grid of squares across the x and y axis of a canvas.
Functions
- What is a function?
A function is a group of rules set to perform a task.
- What is the difference between a function or method built into Processing and one that you define?
A built in function is one that comes with processing. You can call it by typing the variable that the function is assigned to. So for example size() is a built in function, you would just have to include the parameters. A function you define is one where you set a list of things you want the computer to do and assign it to a variable that you can call upon later.
- What does the keyword void mean?
The word void when placed before a function means that the function will not return a value.
- What does the keyword return mean?
The keyword return states that a value
- Write code that uses the keyword return.
- Write code that used a defined function (by the user) and call or use it.
Defined by user means you define the function or what goes in between the curly brackets. An example would be
int x = 0;
int y = width/2;
int xspeed = 2;
int diam = 30;
void setup() {
size(600, 400);
}
void draw() {
background(0);
move(); // call the defined move() function.
display(); // call the defined display() function.
}
// defined functions
void move() {
x = x + xspeed;
}
void display() {
noStroke();
fill(255);
rect(x, y, diam, diam);
}
- What is the distinction between function and method?
- What is the distinction between argument and parameter?
- What do the () in a function call or definition indicate?
The parenthesis is where you include the parameters or the variables that the function attached to the parenthesis will “plug in”.
- What will happen if you call an undefined function?
You will get an error saying “blank” function does not exist or is not defined.
- What will happen if you define a function, but do not call or use it?
It will just float there and waste space. The editor might alert you that its not being used.
- What concept are functions useful for?
Functions are useful for you the user. Since you can assign them to any variable you can call it anything. So instead of
Objects/Classes, Arrays
- What is an object?
- What data type is an object?
- What concept are objects, classes and arrays useful for?
- What is the difference between an object and a class? Use code to demonstrate your response.
- What is dot syntax? Use code to demonstrate your response.
- What is the keyword new used for?
- What is a constructor? Where and when is it used? Use code to demonstrate your response.
- Organize original code to include the main program in one tab and a class in another. Use in-line
comments to walkthrough code.
- What is an array?
- What notation is used to denote an array?
- How do data types impact arrays?
- What is an index?
- Write code that declares, initializes and accesses elements in an array. Use comments to walkthrough code.
- List two or three functions that can be called on an array. Describe how they manipulate the array.