A way to name files in a file system by listing the folders that contain the file before the name of the file. For example, this is how an absolute path name would be written on Windows:
C:\Desktop\courses\fall2011\cmpt166\ball.gif
And on a Mac or Linux system:
/Desktop/courses/fall2011/cmpt166/ball.gif
Compare to relative path name.
In RGB color, the alpha value of a color typically specifies the transparency of that color. For example, this sets the fill color of a shape to be 127, which results in a transparency of about 50%:
fill(0, 255, 0, 127);
In Processing, color alpha values range from 0 (totally transparent) to 255 (totally opaque).
Writing programs intended to be used as applications by non-technical users. For instance, word processors, email clients, and almost all smartphone apps are example of application programs.
Compare to systems programming.
A contiguous sequence of 0 or more objects. For example, here are two arrays:
int[] ages = {18, 18, 17, 19, 20};
println(ages[3]); // prints "19"
float[] dist = new dist[3];
dist[0] = 3.422;
dist[1] = 1.08;
dist[2] = 5.232;
The = symbol is know as the assignment operator in Processing. For instance, this line of code assigns the value -2.01 to variable y:
y = -2.01;
The assignment operator does not work like = in mathematics. For instance, you can write code like this in Processing:
y = y + 1;
This adds 1 to y, which is a useful programming operation. But in mathematics the equation \(y = y + 1\) isn’t very useful because it is equivalent to \(0 = 1\) after you subtract \(y\) from both sides.
The Processing == operator works like the mathematical \(=\) . == is the boolean equality operator, and expression like x == y is a boolean expression that returns true if x and y` have the same value, and ``false otherwise.
A bit is the basic unit of information in computing. A bit has two possible distinct states, often called 0 and 1. Two consecutive bits can represent four distinct states: 00, 01, 10, and 11. Computer’s process all information in terms of bits.
Bit is short for “binary digit”, and was coined by the mathematician John Tukey.
An expression that evaluates to either true or false. For example, these are all boolean expressions:
x < 1
y >= 4 + a
x == y
x - 1 != 2 * y
true
false
false || true
A character in a program beginning and ending with a '. For example, these are all character literals:
'a'
'K'
'7'
'+'
'\n'
'\''
Note that '' is not a character literal: there is no such thing as an empty character (although there is such a thing as an empty string).
Be careful not to confuse character literals — which begin and end with ' — with string literals — which begin and end with ". For example, ‘A’ is a character literal, while “A” is a string literal.
String concatenation is when two, or more strings, are combined to make a new string. For example:
String firstName = "Donald ";
String lastName = "Knuth";
String fullName = firstName + lastName; // "Donald Knuth"
A constructor that takes another object of the same type as input and makes a copy of it, e.g.:
class Point {
int x;
int y;
Point(Point p) { // copy constructor
x = p.x;
y = p.y;
}
}
When specifying the name of a file using a relative path name, the current working folder is the name of the top-most folder that will be searched.
Also know as the current working directory, or present working directory.
A constructor that takes no input parameters, e.g.:
class Point {
int x;
int y;
Point() { // default constructor
x = 0;
y = 0;
}
}
A way of accessing the variables and functions in an object. For example:
String s = "hello";
String t = s.trim();
The expression s.trim() uses dot notation to call the trim() function that belongs to s.
In a string, an escape character is a special code for a character that cannot be directly typed into the string. For example, \n is the newline character, and there is no standard symbol for a newline.
Even though an escape character is more than one character long, it only counts as one character in the string. For example, the string "a\nb\NC" is exactly 5 characters long.
When you print a string with \ns in it, they cause the cursor to move to the next line. For example, println("a\nb\nc") prints this on the console:
a
b
c
The most common escape characters are \n (newline), \\, \", \t (tab), etc.
A visual notation for describing the simple computer programs. For example, the following flow chart shows how Processings setup() and draw() functions are called:
A Processing construct that can be used to access every element in a “term:container object such as an ArrayList. For example, this code prints every string in names:
// names in ArrayList<String> object
for(String s : names) {
println(s);
}
The : inside the loop header can be read as “in”.
A Processing construct that repeats a block of code. For example, this code prints then numbers from 1 to 100:
for(int i = 1; i < 101; ++i) {
println(i);
}
The number of times per second that draw() is called by a Processing program. As long as it doesn’t take too long for draw() to run, Processing calls draw() about 60 times per second by default. The variable frameRate is an estimate of the current frame rate for a Processing program.
You can change the frame rate using the frameRate() function. For example, this sets the frame rate to be 30 frames per second:
frameRate(30);
The statements that get executed when a function is called. For example, the function body of pointInCircle is the code block after the function header (i.e. the first line):
boolean pointInCircle(float x, float y, float a, float b, float r) // function header
{ //
if (dist(x, y, a, b) <= r) { //
return true; //
} else { // function body
return false; //
} //
} //
The first line of a function that declares the function’s return type, name, and input parameters. For example:
boolean pointInCircle(float x, float y, float a, float b, float r) // function header
{
// ... function body ...
}
1 gigahertz (GHz) equals 1000 megahertz (MHz), or one billion hertz (Hz). One hertz means one cycle per second, and so 1 gigahertz means 1 billion cycles per second. If a computer CPU runs at a speed of 1 gigahertz, then that means it can do 1 billion low-level operations (like addition or multiplication) per second.
Modern CPU speeds are often in gigahertz. For instance, if your computer runs at 2.5 GHz, then it does about two and a half billion low-level operations per second.
A variable that can be accessed by any function. In Processing, global variables are variables defined outside of any function. For example, c is a global variable in the following program:
color c = color(255, 0, 0);
void setup() {
size(500, 500);
// ...
}
void draw() {
// ...
}
Compare this to local variable.
An if-statement with an else clause, e.g.:
if (dist(mouseX, mouseY, x, y) <= radius) {
ball_color = color(255, 0, 0);
} else {
ball_color = orange;
}
An if-statement with an else if clause, e.g.:
if (d < 1) {
moving = false;
} else if (d < easingLimit) {
speed = d * maxSpeed / easingLimit;
}
A kind of statement that makes a decision about whether or not to execute a block of code. For example:
if (x == 0) {
println("x is 0");
} else if (x < 0) {
println("x is negative");
} else {
println("x is positive");
}
Usually, the variable declared inside a for-loop header. For instance, in the following code i is the index variable:
for(int i = 1; i < 101; ++i) {
println(i);
}
When two or more animated objects intersect. For example:
Here we say that the ball interpenetrates the wall.
Interpenetration is not allowed when objects are meant to be solid. One common technique for fixing object interpenetration is to adjust the position of the objects so they no longer intersect.
A variable declared inside a function. In Processing, a local variable can only be accessed by code in the function that comes after the declaration. For example, in the following program c is a local variable in draw(), which means it can only be used in the body of draw():
void setup() {
size(500, 500);
// ...
}
void draw() {
color c = color(255, 0, 0);
// ...
}
Compare this to global variable.
A common programming error where the, typically, the value of a variable is thought to be one more, or less, than its true value. This often occurs in loops. For example, the following loop contains an off-by-one error:
int[] arr = new int[6];
for(int i = 0; i <= 6; ++i) { // oops: i gets too big
println(arr[i]);
}
This loop tries to access arr[6], which does not exist.
The natural unit for measuring angles and rotations. To convert degrees into radians, use this formula:
It is already implemented in Processing as degrees, e.g.:
float rad = PI/4;
float deg = degrees(rad);
println(rad + " radians is " + deg + " degrees");
And this formula converts radians into degrees:
It is already implemented in Processing as radians, e.g.:
float deg = 45.0;
float rad = radians(deg);
println(deg + " degrees is " + rad + " radians");
% is the remainder, or mod, operator, and the expression a % b evaluates to the remainder when a is divided by b. The expression a % b is often read as “a mod b”. It is usually assumed that both a and b are integers, and that b is both less than, or equal to, a, and greater than 0.
For example:
10 % 1 evaluates to 0
10 % 2 evaluates to 0
10 % 3 evaluates to 1
10 % 4 evaluates to 2
10 % 5 evaluates to 0
10 % 6 evaluates to 4
10 % 7 evaluates to 3
10 % 8 evaluates to 2
10 % 9 evaluates to 1
10 % 10 evaluates to 0
Text that appears in the source code of a program that is meant as a note to a reader of the source code. Comments have no effect on the program itself, and are automatically stripped out when the program is compiled.
Processing allows two kinds of source code comments:
// this is a single-line comment
/*
This is a multi-line comment.
It can span more than one line.
*/
A string in a program beginning and ending with a ". For example, these are all string literals:
"mouse"
"Once upon a time ..."
"604-555-3536"
"X"
"1\ntwo\nthree"
"Her name is \"Mary\""
"\\n is a return character"
""
Writing programs related to a computer’s operating system. Systems programs often do not interact with the user directly, and instead interface with the operating system. The Cs and C++ languages are popular choices for systems programming.
Compare to applications programming.
A programming language token is a string of 1 or more characters that has some special meaning in the language. For instance, these are all Processing tokens:
=
==
+
-453.2
dx
if
for
void
//
A way of defining logical operators, e.g.:
a b !a a && b a || b false false true false false false true true false true true false false false true true true false true true
In Processing, the type of an object specifies what kind of object it is. For example, some of the built-in numeric types are int (for whole numbers) and float (for decimal numbers). Just by looking at types, Processing can often detect errors without having to run the program, e.g.:
float x = "3.14"; // type error: can't assign a string to a float
A named value. For example, this line declares n to be a variable of type int:
int n = 5;