How to get color to stay once key is pressed?
              in 
             Programming Questions 
              •  
              6 months ago    
            
 
           
             When I pressed the required key, the color changes but when I let go, the color go back to black. How do we get the color to stay? Heres my code.
            
            
             void setup()
             
{
size(400,400);
}
void draw()
{
for(int x=40;x<200;x+=20)
{
//for(int j=40;j<200;j+=20)
{
//ellipse(x,j,5,5);
line(x,250,150,10);
line(x*2,250,150,10);
//strokeWeight(2);
line(40,250,40,400);
line(360,250,360,400);
    
             
}
if(keyPressed)
{
if(key=='r')
{
rect(40,250,320,160);
triangle(150,10,140,40,160,22);
fill(255,0,0);
}
if(key=='b')
{
rect(40,250,320,160);
triangle(150,10,140,40,160,22);
fill(0,0,255);
}
if(key=='g')
{
rect(40,250,320,160);
triangle(150,10,140,40,160,22);
fill(0,255,0);
}
}
       
             
}}
 
           {
size(400,400);
}
void draw()
{
for(int x=40;x<200;x+=20)
{
//for(int j=40;j<200;j+=20)
{
//ellipse(x,j,5,5);
line(x,250,150,10);
line(x*2,250,150,10);
//strokeWeight(2);
line(40,250,40,400);
line(360,250,360,400);
}
if(keyPressed)
{
if(key=='r')
{
rect(40,250,320,160);
triangle(150,10,140,40,160,22);
fill(255,0,0);
}
if(key=='b')
{
rect(40,250,320,160);
triangle(150,10,140,40,160,22);
fill(0,0,255);
}
if(key=='g')
{
rect(40,250,320,160);
triangle(150,10,140,40,160,22);
fill(0,255,0);
}
}
}}
 
              
              1  
            
 
            