Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
How to delete a 2D Primitive in processing?

I'm having a problem to delete 2D primitives, I have tried to create a rectangle in front of those primitives to hide them. But I have to hide them when I click somewhere, so I guess that my draw() overpass the mouseclicked.

In my code, "maFenetre" is what I would like to hide/delete. So this is my code:

float hauteurR = 700;
float barreFenetre = 50;
float xIcone = 80;


float x = random(0,500);
float y = random(0,800);


color rouge = #FF0000;
color blanc = #FFFFFF;

void setup() {
  //colorMode(HSB,360,100,100);
  size(1500,1500); 
  background(#C1C1C1);

  
}

void rectangle(){
rect((x+largeurR)-xIcone,y,xIcone,barreFenetre);
}

void maFenetre(){
      
  
  //fenetre
  noStroke();
  fill(#89E0FF);
  rectMode(CORNER);
  rect(x,y,largeurR,hauteurR);
  
  //barre croix
  rectMode(CORNER);
  fill(blanc);
  noStroke();
  rect(x,y,largeurR,barreFenetre);
  
  if ((mouseX>= (x+largeurR)-xIcone && mouseX <= x+largeurR) && (mouseY >= y && mouseY <= y+barreFenetre)) {
   fill(rouge);
   rectangle();
   
}

   //barre aggrandir
   
   if ((mouseX>= (x+largeurR)-xIcone*2 && mouseX <= (x+largeurR)-xIcone) && (mouseY >= y && mouseY <= y+barreFenetre)) {
   fill(#CEDDDE);
   noStroke();
   rect((x+largeurR)-xIcone*2,y,xIcone,barreFenetre);
   
  }
 
 
 //barre reduire
 
   if ((mouseX>= (x+largeurR)-xIcone*3 && mouseX <= (x+largeurR)-xIcone*2) && (mouseY >= y && mouseY <= y+barreFenetre)) {
   fill(#CEDDDE);
   noStroke();
   rect((x+largeurR)-xIcone*3,y,xIcone,barreFenetre);
   }
   
   
   //icone réduire
   
   stroke(#000000);
 strokeWeight(2);
 line((x+largeurR)-xIcone*2.65,y+barreFenetre/2,(x+largeurR)-xIcone*2.35,y+barreFenetre/2);
   
   
 //icone aggrandir
 
 stroke(#000000);
 strokeWeight(2);
 noFill();
 rectMode(CENTER);
 rect((x+largeurR)-xIcone*1.5,y+barreFenetre/2,20,20);
 

  //icone croix
  stroke(#030303);
  strokeWeight(2.5);
  line((x+largeurR)-xIcone*0.62,y+barreFenetre*0.35,(x+largeurR)-xIcone*0.38,y+barreFenetre*0.75);
  line((x+largeurR)-xIcone*0.62,y+barreFenetre*0.75,(x+largeurR)-xIcone*0.38,y+barreFenetre*0.35);
    
  }
  
void draw() {

maFenetre();

  


}


void mouseReleased(){
  if (mousePressed == ((mouseX>= (x+largeurR)-xIcone && mouseX <= x+largeurR) && (mouseY >= y && mouseY <= y+barreFenetre))){
  }
    else{
    //background(#C1C1C1);
    noStroke();
    rectMode(CORNER);
    fill(#C1C1C1);
    rect(x-1,y-1,largeurR+2,hauteurR+2);
  //maFenetre();

}
  
  
  
}```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Deleting an object not drawing it. Add a variable that indicates whether an object needs to be drawn. Change the status of the variable if you want to hide (or show) the object:

boolean drawMyObject = true;

void draw() {
    // [...]


    rectMode(CORNER);
    if (drawMyObject) {
        rect(x, y, w, h);
    }
}

void mouseReleased(){
    if (mouseX >= x-w/2 && mouseX <= x+w/2 && mouseY >= y-h/2 && mouseY <= y+h/2){
        drawMyObject = false;
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!