# Mouseclicked question

**URL:** https://discourse.processing.org/t/mouseclicked-question/47536
**Category:** Beginners
**Created:** [November 13, 2025, 2:46pm UTC](https://discourse.processing.org/t/mouseclicked-question/47536 "2025-11-13T14:46:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![darfurspacengine](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@darfurspacengine](https://discourse.processing.org/u/darfurspacengine)
#### Post date: [November 13, 2025, 2:46pm UTC](https://discourse.processing.org/t/mouseclicked-question/47536/1 "2025-11-13T14:46:48Z")

</div>

Is there a way to have the draw function, in that it runs 60 times a second, happen after mouseclick?

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [November 13, 2025, 3:02pm UTC](https://discourse.processing.org/t/mouseclicked-question/47536/2 "2025-11-13T15:02:26Z")

</div>

Welcome to the forum.

The solution depends on what mode you are using. This sketch uses Java mode and shows one possible solution.

```auto
float ang = 0;

void setup(){
  size(300,400);
  noLoop(); // Stop draw method after first frame
}

void draw(){
  background(40);
  ang += 0.01;
  translate(width/2, height/2);
  rotate(ang);
  stroke(255);
  fill(64,64,255);
  strokeWeight(4);
  rectMode(CENTER);
  rect(100,0,80,30);
}

void mouseClicked(){
  loop(); // start looping 60fps
}

```

---

<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: [November 13, 2025, 3:42pm UTC](https://discourse.processing.org/t/mouseclicked-question/47536/3 "2025-11-13T15:42:11Z")

</div>

> [@quark](#):
>
> ```auto
> void mouseClicked() {
> loop(); // start looping 60 FPS
> }
> 
> ```

To refresh the canvas for each press of the mouse, we can use **noLoop()** in **setup()** + **redraw()** in **mousePressed()**:

```auto
void mousePressed() {
  redraw(); // run draw() once
}

```

> **[mousePressed() / Reference](https://processing.org/reference/mousepressed_)**
>
> The mousePressed() function is called once after every time a mouse button is pressed. The mouseButton variable (see the related reference entry) can be used to determine which button ha…

> **[redraw() / Reference](https://processing.org/reference/redraw_.html)**
>
> Executes the code within draw() one time. This functions allows the program to update the display window only when necessary, for example when an event registered by mousePressed() or

The same approach also works on the p5js flavor btW:

> **[mousePressed](https://p5js.org/reference/p5.Element/mousePressed/)**
>
> mousePressed

> **[redraw](https://p5js.org/reference/p5/redraw/)**
>
> redraw

---

<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: [November 13, 2025, 4:36pm UTC](https://discourse.processing.org/t/mouseclicked-question/47536/4 "2025-11-13T16:36:20Z")

</div>

> [@darfurspacengine](#):
>
> Is there a way to have the draw function, in that it runs 60 times a second, happen after mouseclick?

Yes!

You did not provide much context so sharing enough to get you started.

Some references:

- [Interactivity / Processing.org](https://processing.org/tutorials/interactivity)
- [frameRate() / Reference / Processing.org](https://processing.org/reference/frameRate_.html)
- [noLoop() / Reference / Processing.org](https://processing.org/reference/noLoop_.html)

Setting the _frameRate()_ may not always work depending on renderer and video card settings. That is another discussion.

Have fun!

Useful guides here as well:  
_[Welcome to the Processing Foundation Discourse](https://discourse.processing.org/t/welcome-to-the-processing-foundation-discourse/8)_ \< The _Asking Questions_ is a must read!

`:)`
