There is nothing wrong.
The first example i posted in this topic is keeping the same shape, but just changing its color.
The reason why your code is not working as you expect is because draw() is diplaying objects as layer (check the example below).
Quote:void setup()
{
size(500,500);
print("setup \n");
frameRate(1);
}
void draw()
{
background(255,0,0); // in background, layer 0.
Ellipse();// in middle, layer 1.
Rectangle();// in front, layer 2.
}
void Ellipse()
{
fill(255);
ellipse(random(200),200,200,200);
print("a");
// delay(1000);
}
void Rectangle()
{
fill(0);
rect(0,random(200),200,300);
print("b");
// delay(1000);
}
The ellipse() called in draw() will be drawn the first, then the rectangle() will be drawn on top of the ellipse().
When draw() will reach the end, it will restart drawing:
the background first
the ellipse on top of the background
the rectangle on top of the background and the ellipse.
Quote: BACK
----------
background()
Ellipse()
Rectangle()
----------
FRONT
if you want to switch from one shape to another you must use boolean to activate/disactivate the objects or switch their position in draw().
Here is an example of switching objects layer position by using boolean.
Quote:boolean rectanglefront;
void setup()
{
size(500,500);
frameRate(1);
rectanglefront = true;
}
void draw()
{
background(255,0,0);
if(rectanglefront){
Ellipse();
Rectangle();
rectanglefront = false;
print("rectangle is in front ");
}else{
Rectangle();
Ellipse();
rectanglefront = true;
print("ellipse is in front ");
}
}
void Ellipse()
{
fill(255);
ellipse(random(200),200,200,200);
}
void Rectangle()
{
fill(0);
rect(0,random(200),200,300);
}