No, these are global variables meaning they are accessible everywhere in the code (inside functions, loops… and more generally any blocks).
int globalVariable = 0;
void example() {
int localVariableToTheExampleFunction = 1;
println(globalVariable); // Accessible here
}
example(); // Prints 0
println(localVariableToTheExampleFunction); // Error: not defined in this scope
This is the notion of scope in computer science.
This is a common practice to put global variables at the top of your program so modifying and reading them is easy. In this case, I am just declaring a variable that controls the maximum height that points can have using the z
coordinate (pointing from you from the window point of view).
You need to understand how object oriented programming works (using classes with the class
) keyword. See a previous message I did on the subject:
To summarize, I am using a Grid
class that describes the grid you want to display. It has a points
attribute which is a 2D array of PVector (which is itself a class holding up to three coordinates x
, y
, z
).
This is perfect since we want to handle 3D points organized in a grid (rows and columns).
A class has a constructor, it’s a special “method” with some parameters used to initialize the object (in this case the Grid):
class Grid {
Grid(int resolution, int borderGap) {
// Initialize the grid here (mainly point coordinates)
}
}
Try to read the code and understand what each part does before trying to copy paste code at some places.