# Progress bar from inside draw()

**URL:** https://discourse.processing.org/t/progress-bar-from-inside-draw/12091
**Category:** Coding Questions
**Created:** [June 16, 2019, 9:14am UTC](https://discourse.processing.org/t/progress-bar-from-inside-draw/12091 "2019-06-16T09:14:40Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [June 17, 2019, 12:43am UTC](https://discourse.processing.org/t/progress-bar-from-inside-draw/12091/6 "2019-06-17T00:43:11Z")

</div>

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:

- [https://forum.processing.org/two/discussion/5886/multithreading-madness](https://forum.processing.org/two/discussion/5886/multithreading-madness)
- [Problems when trying to draw to a P3D PGraphics when called from a thread?](https://discourse.processing.org/t/problems-when-trying-to-draw-to-a-p3d-pgraphics-when-called-from-a-thread/6301/4)

---

_[View the full topic](https://discourse.processing.org/t/progress-bar-from-inside-draw/12091)._
