In this article, I will explain how the settings ()
, setup ()
, and draw ()
of Processing 3.3.5 (latest as of 7/2) work. It is not a description of the IDE.
If you have any mistakes or more interesting information, please let us know in the comments!
https://github.com/processing/processing
This is the official source code for the Processing Development Environment (PDE), the “core” and the libraries that are included with the download.
So I will read the official source code of Processing.
You can read more about how Processing works in core / src / processing.
settings ()
, setup ()
, and draw ()
All three of these functions are defined in PApplet.java. Let's look at each one.
settings()
public void settings() {
// is this necessary? (doesn't appear to be, so removing)
//size(DEFAULT_WIDTH, DEFAULT_HEIGHT, JAVA2D);
}
setup()
public void setup() {
}
draw()
public void draw() {
// if no draw method, then shut things down
//System.out.println("no draw method, goodbye");
finished = true;
}
The code you are writing in Processing is actually a class that inherits from PApplet
. When I run the following code, it returns true
.
println(this instanceof PApplet);
Processing is written on the assumption that it will override settings ()
, setup ()
, and draw ()
of PApplet
. Writing @Override
before the code does not give an error.
settings ()
is called by a function called handleSettings ()
.
Also, setup ()
and draw ()
are called by the function handleDraw ()
.
Both are in PApplet
.
handleSettings()
After this, in PApplet
, it will be called in the order ofrunSketch ()
⇒main ()
.
As an aside, a boolean variable called ʻinsideSettingsis used in this function. Processing's
smooth ()and
noSmooth () only work if the variable ʻinsideSettings
is true. Note that processing can only be done in the true state in settings ()
. There was actually a person in need.
handleDraw()
setup ()
is called when frameCount == 0
, anddraw ()
is called otherwise. This is also a small story, but since frameCount
is a public variable, you can freely change the numerical value. If you do it inside frameCount = -1
anddraw ()
,setup ()
will be called. You won't have a chance to use it, but it's one of the processing vulnerabilities.
AnimationThread
A Thread called AnimationThread is defined in the class PSurfaceNone
. handleDraw ()
is called by callDraw ()
in it, and continues to loop in run ()
until the end condition is met by the while statement.
So far, I have explained how the settings ()
, setup ()
, and draw ()
that we always wrote in Processing work. I hope you are satisfied with this article.
handleDraw ()
is public and can be overridden. Just put the following code in someone else's code and setup ()
and draw ()
will not be called.
void handleDraw() {
}
This is also a Processing vulnerability. Is it okay Processing ...
Recommended Posts