Arashjot Kaur
Arashjot Kaur

Reputation: 51

How do I reset a processing canvas on key press?

I am trying to create a reset button in processing that would let the user press a key and the canvas would reset and become blank. I used the keyPressed function but it doesn't work.

void setup(){
 size(900,900);
 background(25, 57,0);
}

void draw(){
 if(mousePressed){
 ellipse(mouseX,mouseY,30,40);
 fill(255,255,255);
 stroke(200,100,100);
 }
 if(keyPressed==true){

 }

 saveFrame();
 }

Upvotes: 2

Views: 407

Answers (1)

Chris
Chris

Reputation: 1321

Just reset the background color to what it was initially:

void setup(){
    size(900,900);
    background(25, 57,0);
}

void draw(){
    if(mousePressed){
       ellipse(mouseX,mouseY,30,40);
       fill(255,255,255);
       stroke(200,100,100);
    }
    if(keyPressed==true){
       background(25, 57,0); //resets background
    }
    saveFrame();
}

Upvotes: 1

Related Questions