Progress bar from inside draw()

Another way to approach this is to kick off a thread and do the render calculations on an int array. When the thread finishes, set a flag to done so you can copy the int array into a PImage or PGraphics and draw the image. In the meantime, draw is looping at 60fps – not only could you draw a progress bar in your main window, you have full UI – for example, to cancel or quit.

Note that this makes sense for iterating over integers with a math library, but not for drawing – drawing in a thread does not work by default due to the single-threaded design of Processing PGraphics, and working around that can be a real pain. This includes using color() in a thread – don’t do it. For more on why, see:

1 Like