Mouseclicked question

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

Welcome to the forum.

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

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
}
2 Likes

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

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

The same approach also works on the p5js flavor btW:

3 Likes

Yes!

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

Some references:

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 < The Asking Questions is a must read!

:)