(NOOB) How to keep a shape on screen after I release the mouse click?

Hey guys, super noob here. I have a simple code where when I left click it produces a red dot, and when I right click it produces a blue dot. When I release my click the dot disappears. How do I get the dot to stay on the screen?

void setup() {
size (500, 500);
background (150, 100, 50);
}
void draw(){
if (mousePressed && (mouseButton == LEFT)) {
stroke (255, 0, 0);
fill (255, 0, 0);
ellipse (mouseX, mouseY, 5, 5);

} else if (mousePressed && (mouseButton == RIGHT)) {
stroke (0, 0, 255);
fill (0, 0, 255);
ellipse (mouseX, mouseY, 5, 5);

} else {
background (150, 100, 50);
}

}

remove this. Add something like

<your current code>
<...>
void keyPressed() {
   if(key == ' ') background(150,100,50) //reset screen if you press space
}

here is the new code:

Code
void setup() {
  size (500, 500);
  background (150, 100, 50);
}
void draw() {
  if (mousePressed && (mouseButton == LEFT)) {
    stroke (255, 0, 0);
    fill (255, 0, 0);
    ellipse (mouseX, mouseY, 5, 5);
  } else if (mousePressed && (mouseButton == RIGHT)) {
    stroke (0, 0, 255);
    fill (0, 0, 255);
    ellipse (mouseX, mouseY, 5, 5);
  }
}
void keyPressed() { 
  if (key == ' ') background(150, 100, 50);
}

1 Like

Thank you so much! Very new to this lol but this fixed it

1 Like

Glad to help!
Have a fun learning!

1 Like