Processing works in two modes:
Static mode is just a bunch of function calls. In this mode, Processing just draws a single image and then stops. Here's an example:
background(32);
ellipse(10, 20, 50, 50);
Active mode is a sketch that contains functions like setup()
and draw()
. In this mode, Processing continues executing code after the program starts: for example it executes draw()
60 times per second, or mousePressed()
when the user presses the mouse. Here's an example:
void draw(){
background(32);
ellipse(mouseX, mouseY, 25, 25);
}
The problem with your sketch is that Processing doesn't know which mode you're trying to use. It sees that you don't have a setup()
or draw()
function (or any other Processing callback function), so it thinks you're trying to use static mode. But then it sees you've defined a non-callback function, so it doesn't know how to work.
Like you've discovered, the solution to your problem is to add other functions, so Processing can know what mode you want to be in. Also note that none of your code makes a ton of sense by itself, because Processing has no way of accessing it. My guess is you're planning on adding setup()
and draw()
functions eventually, so just add them now to get rid of your error.
For more info:
- See George's answer here.
- See my answer here.
- See this GitHub issue where the creator of Processing explains all of the above.