Skip to content

Instantly share code, notes, and snippets.

@robynitp
Last active December 27, 2015 12:58
Show Gist options
  • Save robynitp/7329363 to your computer and use it in GitHub Desktop.
Save robynitp/7329363 to your computer and use it in GitHub Desktop.
Basic OOP in Processing
// --- Processing ---//
/*
Declare and construct an object from the class HLine
Processing requires that you state the type of a variable when you initialize it.
The type here is HLine
*/
HLine h1 = new HLine(20, 2.0);
// show the ypos property of h1
print(h1.ypos);
class HLine {
// Properties, like variables, must include the data type. Here it's float.
float ypos, speed;
// The constructor
// In Processing the constructor is named the same as the class
HLine (float y, float s) {
// In Processing, you don't have to use 'this' to get a property
ypos = y;
speed = s;
}
/*
methods in Processing have to start with the data type of the return value
this function doesn't return anything, so it starts with "void"
all parameters also have to have a data type
*/
void doSomething(int num) {
// do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment