[SOLVED] Delete circles if mousePressed help?

I’m trying to figure out what’s the code to make the circles disappear if the mouse is pressed. If you know what it is, please share it! I pasted my code below thanks!

// Lab 3 Question 7
// Write a program that draws a red circle on a black background on the right hand side of the screen and a white circle on a grey background on the left hand side of the screen.
// If the mouse is pressed, the window should reset (the circles should disappear).

void setup()
{
  background(255); // White background
  size(500,500); // Canvas size is 500x500
  
  noStroke(); // No outline
  
  fill(0,0,0); // Black
  rect(250,0,250,500); // Right
  
  fill(100,100,100); // Grey
  rect(0,0,250,500); // Left  
}

void draw()
{
  if(mouseX < 250 == true) // 250 is the middle, so if you move the mouse more than 250 from the black background, it turns white, otherwise it stays red
  **if(mousePressed == true) // If the mouse is pressed, it will make the circles disappear ???**
{  

  fill(255,255,255); // White circle
  } else {
  fill(255,0,0); // Red circle
  }
  ellipse(mouseX,mouseY,40,40); // Draws a 40x40 circle wherever the mouse is
  stroke(0,0,0); // Black outline
}

// Lab 3 Question 7
// Write a program that draws a red circle on a black background on the right hand side of the screen and a white circle on a grey background on the left hand side of the screen.
// If the mouse is pressed, the window should reset (the circles should disappear).

float d;
color value;

void setup()
{
  background(255); // White background
  size(500, 500); // Canvas size is 500x500

  noStroke(); // No outline

  fill(0, 0, 0); // Black
  rect(250, 0, 250, 500); // Right

  fill(100, 100, 100); // Grey
  rect(0, 0, 250, 500); // Left
  d = 40;
}

void draw() {
  if (mouseX < 250  == true) {
    value = color(255, 255, 255); // set value to white
  } else {
    value = color(255, 0, 0); // set value to red
  }
  fill(value); // fill the ellipse with the value according to the condition of the mouseX
  ellipse(mouseX, mouseY, d, d); // Draws a 40x40 circle wherever the mouse is
  stroke(0, 0, 0); // Black outline
  //if (mousePressed) { // here comes the vanishing part
  //  noStroke(); 
  //  fill(0, 0, 0); 
  //  rect(250, 0, 250, 500); 
  //  fill(100, 100, 100); 
  //  rect(0, 0, 250, 500);
  //}

  // you can do it with the function mouseClicked(), but the way of doing that would be, it is very specific to only clicking, because if you press the mouse button, does not activate the vanishing part, only clicking.
}
void mouseClicked() {
  noStroke(); 
  fill(0, 0, 0); 
  rect(250, 0, 250, 500); 
  fill(100, 100, 100); 
  rect(0, 0, 250, 500);
}

i guess is that what u want

Thanks it worked! I used if(mousePressed) instead of void mouseClicked() and I placed it inside void draw(). When the mouse is pressed it deletes any circles and won’t let me draw any unless I let it go.

void draw()
{
  if(mouseX < 250 == true) // 250 is the middle, so if you move the mouse more than 250 from the black background, it turns white, otherwise it stays red
  {
    fill(255, 255, 255); // White circle
  } else {
    fill(255, 0, 0); // Red circle
  }
  ellipse(mouseX, mouseY, 40, 40); // Draws a 40x40 circle wherever the mouse is
  stroke(0, 0, 0); // Black outline
  if (mousePressed) // If you press the mouse, it will make the circles you drew disappear
  {
    noStroke();
    fill(0, 0, 0); // Black
    rect(250, 0, 250, 500); // Right

    fill(100, 100, 100); // Grey
    rect(0, 0, 250, 500); // Left
  }
}
1 Like