Constant ellipse when mouse clicked

void mousePressed(){
    ellipse(Projpos.x, Projpos.y, 100, 100);
}

Hi, i have a problem where i’d like to spawn an ellipse each time the mouse is pressed but when i pressed my mouse an ellipse spawn just for 1 second

1 Like

Hi,

Welcome to the community! :slight_smile:

The thing to remember is that the draw() function is being executed roughly 60 times per second. So if each time you draw a white background like this :

void draw(){
  // White background
  background(255);
}

then you are going to clear the window each frame. It means that if you draw an ellipse when you press your mouse, it’s going to disappear next frame.

You have two solutions :

  • You can remove the background(255); instruction in the draw function and put it in the setup function so it’s only going to draw a white background at the beginning of the sketch and your ellipses are going to stay printed on the screen. It’s not the best solution because it means that everything that you draw is going to stay on the screen…

  • The second solution is more adaptable : you need to store the position of your ellipses in an array each time you press the mouse and then each frame re-draw those ellipses.
    I suggest you use ArrayList to store some PVector representing the locations of your ellipses.

4 Likes