sponge := proc(a,b,c,L,v,m) description `returns the Menger Sponge`; local p,np,i,j,k; if v = 0 then p := [plottools[hexahedron]([a,b,c],L,style=line)]: else p := []: end if; for i from -1 to +1 do for j from -1 to +1 do for k from -1 to +1 do if abs(i) + abs(j) + abs(k) = 1 then np := plottools[hexahedron]([a+2*i*L/3,b+2*j*L/3,c+2*k*L/3],L/3): p := [op(p),np]: end if; end do; end do; end do; if v < m then for i from -1 to +1 do for j from -1 to +1 do for k from -1 to +1 do if abs(i) + abs(j) + abs(k) > 1 then np := sponge(a+2*i*L/3,b+2*j*L/3,c+2*k*L/3,L/3,v+1,m): p := [op(p),op(np)]: end if; end do; end do; end do; end if; return p; end proc;