# Update screen immediately

**URL:** <https://discourse.processing.org/t/update-screen-immediately/26856>\
**Category:** Coding Questions\
**Created:** [January 7, 2021, 12:51pm UTC](https://discourse.processing.org/t/update-screen-immediately/26856 "2021-01-07T12:51:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![edumanilha](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@edumanilha](https://discourse.processing.org/u/edumanilha)\
**Post date:** [January 7, 2021, 12:51pm UTC](https://discourse.processing.org/t/update-screen-immediately/26856/1 "2021-01-07T12:51:39Z")

</div>

Hi everyone! How are you people doing?

I need some help…

I put a button on my script to change some values on screen, but I set framerate to update every second, so every time I click the value take some time to update and thats not practical…Searching a solution I found redraw(); but, it doesn’t seen to be working…Still update every second and not right on click! Any hint How can I take imediate action ignoring the framerate? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 7, 2021, 1:25pm UTC](https://discourse.processing.org/t/update-screen-immediately/26856/2 "2021-01-07T13:25:05Z")

</div>

> [@edumanilha](#):
>
> , but I set framerate to update every second,

So that’s the minimum delay between each **draw()** callback.

If you have actions in your sketch which should happen at different delays you’re gonna need to manage that.

You can base that on [**millis()**](https://processing.org/reference/millis_.html) or [_frameCount_](https://processing.org/reference/frameCount.html) for example.

Or use some library for that. Here’s 1 I’ve made:

> <https://gist.github.com/GoToLoop/ea4db8a8622e27541213da3c9a43ca21>

---

<div class="post-metadata">

**Author:** ![rbrauer](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rbrauer](https://discourse.processing.org/u/rbrauer)\
**Post date:** [January 7, 2021, 10:59pm UTC](https://discourse.processing.org/t/update-screen-immediately/26856/3 "2021-01-07T22:59:15Z")

</div>

Maybe try calling draw() instead of redraw().

---

<div class="post-metadata">

**Author:** ![edumanilha](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@edumanilha](https://discourse.processing.org/u/edumanilha)\
**Post date:** [January 18, 2021, 3:07am UTC](https://discourse.processing.org/t/update-screen-immediately/26856/4 "2021-01-18T03:07:00Z")

</div>

Thanks guys! sorry for the late response! @rbrauer calling draw(); worked like a charm! Thanks!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 18, 2021, 8:45am UTC](https://discourse.processing.org/t/update-screen-immediately/26856/5 "2021-01-18T08:45:39Z")

</div>

I think technically this is a very bad idea

@rbrauer

---

<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:** [January 18, 2021, 10:26am UTC](https://discourse.processing.org/t/update-screen-immediately/26856/6 "2021-01-18T10:26:26Z")

</div>

> [@rbrauer](#):
>
> Maybe try calling draw() instead of redraw().

@rbrauer @edumanilha

Hello,

Can you provide a minimal example? Just for clarity…

An interactive program has the functions setup() and draw() and discussed in the _Hello Mouse_ section:  
[https://processing.org/tutorials/overview/](https://processing.org/tutorials/overview/)

Are you doing something different?

`:)`

---

<div class="post-metadata">

**Author:** ![edumanilha](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@edumanilha](https://discourse.processing.org/u/edumanilha)\
**Post date:** [January 18, 2021, 1:24pm UTC](https://discourse.processing.org/t/update-screen-immediately/26856/7 "2021-01-18T13:24:29Z")

</div>

Hi! I have a mouseclicked function that add ou subtract time values, I need to update screen when clicked and no the framerate I set (every one second), so I just do what I need (add value to timer) and call the draw to update the screen every time the value changes and not waiting 1 second, that in case is a long time and can generate under or over clicks!..

---

<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:** [January 18, 2021, 5:20pm UTC](https://discourse.processing.org/t/update-screen-immediately/26856/8 "2021-01-18T17:20:14Z")

</div>

Hello,

Can you provide a simple code example please?

This may be of interest:  
[https://processing.org/reference/loop\_.html](https://processing.org/reference/loop_.html)

`:)`

---

<div class="post-metadata">

**Author:** ![rbrauer](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rbrauer](https://discourse.processing.org/u/rbrauer)\
**Post date:** [January 18, 2021, 7:47pm UTC](https://discourse.processing.org/t/update-screen-immediately/26856/9 "2021-01-18T19:47:48Z")

</div>

Try this I think it demonstrates the timing difference. Clicking (redraw()) when the background is red continues through the rest of the red frame, then one green frame, then blue. Keyboard (draw()) when the background is red you get the rest of the red frame then blue.

```auto
int tog;

void setup() {
  frameRate(0.5);
}

void draw() {
  background(new int[] {
    color(255, 0, 0), 
    color(0, 255, 0),
    color(0, 0, 255)
  }[tog]);
  tog++;
  tog %= 2;
}

void mouseClicked() {
  tog = 2;
  redraw();
}

void keyPressed() {
  tog = 2;
  draw();
}

```

---

<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:** [January 19, 2021, 11:45pm UTC](https://discourse.processing.org/t/update-screen-immediately/26856/10 "2021-01-19T23:45:07Z")

</div>

Hello @rbrauer

I simplified this:

> [@rbrauer](#):
>
> ```auto
> background(new int[] {
> color(255, 0, 0), 
> color(0, 255, 0),
> color(0, 0, 255)
> }[tog]);
> 
> ```

To this:

```auto
  int c3 = 0x00FF0000;
  background( (c3 >>(8*tog)) | 0xFF000000 );

```

`:)`
