mousePressed() function

when dealing with p5.js, note that everything on the canvas is redraw every intended milliseconds or seconds. for example. you can call frame rate(or frame draw or setTimeout) every time you want a new frame to be drawn. that determines the rate at which your program is displayed to the end user.

now for your problem you are having,the background simply redraws itself so don’t expect it to work. the best thing is to add a counter or a boolean instance.

eg.

let us use the less glitchy way of approaching your problem. that is the counter.

int showCirle = 0;

if(mousePressed){
 showCircle=1;
//nested loop
if(showCircle>1){
 showCircle=0;}
}
//now the above function is to make sure this falls back to zero when showCircle has past one
//now for the real deal
if(showCircle==1){
fill(255,0,0);//red
eclipse(500,500,20);//or use ur own circle(500,500,20); assuming its an object you made.
}

this should work just fine. why don’t you check it out and see for yourself.