At some point in coding, it will become necessary to create one’s own functions. All that needs to be done to create one, is to name and declare that function and use it. For example, I will show you how to declare a function called redCircles. As the name might tell you, it should create red circles.
EXAMPLE:
void redCircles() {
noStroke();
fill(255, 0, 0);
ellipse(100, 100, 30, 30);
}
The function is created. If you call the function redCircles(); now anywhere in your code, Processing will execute what you have defined for that function. As a further step, one can create functions with arguments. This can help you to e.g. create circles where you can determine the size and the position every time you call that function. So when creating a function with arguments, you must add theses kinds of arguments according to the example below.
EXAMPLE:
Void redCircles(float posx, float posy, float diameter) {
noStroke();
fill(255, 0, 0);
ellipse(posx, posy, diameter, diameter);
}
The arguments you describe must indicate the variable type, like here float. After that, you give your variable a name. Inside of the function you must use the defined arguments. If you now would want a circle at the x-position 200 and y-position 70 with a diameter of 25, you must call the function like this:
redCircles(200, 70, 25);
The program will automatically bring these values to the spots you used them in your function declaration.