# Controlling the drawing flow of Processing

**URL:** <https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979>\
**Category:** Development\
**Created:** [May 12, 2023, 4:31pm UTC](https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979 "2023-05-12T16:31:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidGR74](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/davidgr74/32/18371_2.png) [@DavidGR74](https://discourse.processing.org/u/DavidGR74)\
**Post date:** [May 12, 2023, 4:31pm UTC](https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979/1 "2023-05-12T16:31:35Z")

</div>

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:

```auto
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!!

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 12, 2023, 4:54pm UTC](https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979/2 "2023-05-12T16:54:02Z")

</div>

Hello @DavidGR74,

Lots to explore here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

See:

- [redraw() / Reference / Processing.org](https://processing.org/reference/redraw_.html)
- [Redraw / Examples / Processing.org](https://processing.org/examples/redraw.html)
- [noLoop() / Reference / Processing.org](https://processing.org/reference/noLoop_.html)
- [No Loop / Examples / Processing.org](https://processing.org/examples/noloop.html)
- There may be more… always check the related at the bottom of each reference.
- A search on the Processing website above for keywords such as _loop_ will find examples or peruse the examples.

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 13, 2023, 10:22am UTC](https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979/3 "2023-05-13T10:22:45Z")

</div>

Hello again @DavidGR74,

You can also use a timer.

One example here:  
_[timer | Learning Processing 2nd Edition](http://learningprocessing.com/examples/chp10/example-10-04-timer)_

There is a _delay()_ function but it clearly states:

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

`:)`

---

<div class="post-metadata">

**Author:** ![DavidGR74](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/davidgr74/32/18371_2.png) [@DavidGR74](https://discourse.processing.org/u/DavidGR74)\
**Post date:** [May 14, 2023, 5:49pm UTC](https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979/4 "2023-05-14T17:49:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DavidGR74](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/davidgr74/32/18371_2.png) [@DavidGR74](https://discourse.processing.org/u/DavidGR74)\
**Post date:** [May 14, 2023, 5:50pm UTC](https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979/5 "2023-05-14T17:50:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 14, 2023, 7:33pm UTC](https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979/6 "2023-05-14T19:33:02Z")

</div>

Hello,

> [@DavidGR74](#):
>
> call manually

Can you elaborate?

These may be of interest:

> **[PGraphics / Reference](https://processing.org/reference/PGraphics.html)**
>
> Main graphics and rendering context, as well as the base API implementation for processing "core". Use this class if you need to draw into an off-screen graphics buffer. A PGraphics object can be cons…

> **[Render Techniques](https://processing.org/tutorials/rendering/)**
>
> Tools for rendering geometries in Processing.

`:)`

---

<div class="post-metadata">

**Author:** ![DavidGR74](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/davidgr74/32/18371_2.png) [@DavidGR74](https://discourse.processing.org/u/DavidGR74)\
**Post date:** [May 15, 2023, 7:16pm UTC](https://discourse.processing.org/t/controlling-the-drawing-flow-of-processing/41979/7 "2023-05-15T19:16:04Z")

</div>

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

```auto
//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.
