% modified from Professor Militzer's code for a Menger Sponge

function sponge(n,r,L,color)

if (n==1) 
    %cube(r,L,color);          %choose for the cubic step
    square_pyramid(r,L,color); %choose for the square pyramid step
    return
end

L = L / 2;
n = n - 1;
x = [ L; 0; 0];
y = [ 0; L; 0];
z = [ 0; 0; L];

sponge(n,r,L,color);
sponge(n,r+x,L,color);
sponge(n,r+y,L,color);
sponge(n,r+x+y,L,color);
sponge(n,r+1/2*x+1/2*y+z,L,color);

end
