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

function square_pyramid(r,L,color)

x = [ L; 0; 0];
y = [ 0; L; 0];
z = [ 0; 0; L];

square(r,x,y,color);

a(1)=r(1)+L;      b(1)=r(2);        c(1)=r(3);
a(2)=r(1)+L/2;    b(2)=r(2)+L/2;    c(2)=r(3)+L;
a(3)=r(1);        b(3)=r(2);        c(3)=r(3);
patch(a,b,c,color);

a(1)=r(1);        b(1)=r(2)+y(2);   c(1)=r(3);
a(2)=r(1)+L/2;    b(2)=r(2)+L/2;    c(2)=r(3)+z(3);
a(3)=r(1);        b(3)=r(2);        c(3)=r(3);
patch(a,b,c,color);

a(1)=r(1)+x(1);   b(1)=r(2)+y(2);   c(1)=r(3);
a(2)=r(1)+L/2;    b(2)=r(2)+L/2;    c(2)=r(3)+z(3);
a(3)=r(1);        b(3)=r(2)+y(2);   c(3)=r(3);
patch(a,b,c,color);

a(1)=r(1)+x(1);   b(1)=r(2)+y(2);   c(1)=r(3);
a(2)=r(1)+L/2;    b(2)=r(2)+L/2;    c(2)=r(3)+z(3);
a(3)=r(1)+x(1);   b(3)=r(2);        c(3)=r(3);
patch(a,b,c,color);

end
