Controlling the drawing flow of Processing

Hello, this is my first message here.

I’ve been developing for 3 years a library called JMathAnim to create mathematical animations, as an alternative to the Python manim library. So far it uses JavaFX as a renderer, but its 3D capabilities are very limited and I’m considering implementing it using Processing.
The problem is that, from what I’ve seen, the flow of a program in Processing is a continuous loop of the draw() method.
My library uses a method similar to manim. For example:

Shape c=Shape.circle(); //Create a circle. No frame is generated.
play.showCreation(c);//Play a circle creation animation, 3 seconds long. Creates several frames and encodes them into a video queue.
waitSeconds(3);//Creates 3 seconds of static image.Creates several frames and encodes them into a video queue.

and the program ends its execution. I want Processing to take care of rendering the objects on demand, and I would like to know if I can control the call to the draw() method manually and without a continuous loop.
Thanks!!

2 Likes

Hello @DavidGR74,

Lots to explore here:

See:

:)

2 Likes

Hello again @DavidGR74,

You can also use a timer.

One example here:
timer | Learning Processing 2nd Edition

There is a delay() function but it clearly states:

For instance, you cannot use delay() to control the timing of an animation.

:)

Thank you glv, but it is not what I’m looking. What I am trying to achieve is to call manually every render of a frame from my own program loop, in order to use Process as a on-demand renderer.

Thank you very much! I will take a deep look at that methods.

Hello,

Can you elaborate?

These may be of interest:

:)

Thank you, yes, the PGraphics class can be useful.
The current version of my library uses methods to generate video animations. I do this by progressively creating frames with each command and encoding them into a movie. For example:

//Creates a Shape object but not any frame
Shape c=Shape.square(); 
//Plays an animation of 3 seconds, shifting the square one unit to the right.
//It generates 90 frames (for a 30 fps configuration) so it calls 90 times to the renderer.
play.shift(3,1,0,c);

As you can see, the workflow is different from the usual Processing workflow. When the commands are finished executing, the program terminates, there is no infinite loop like draw().

Currently, the renderer in my program is implemented with the JavaFX graphics libraries, which gives a good result in 2D but is quite limited in 3D, so I want to explore other alternatives.