function tetraSG(m)

%This plots the tetrahedral sierpinski gasket of level m in three
%dimensions (pretty cool).

v0=[1/2 1 0; 0 0 0; 1 0 0; 1/2 1/2 1];
y=v0;
for n=1:1:m
    v=y;
    for i=1:1:4
        for j=1:1:max(size(y))
            v=[v; 1/2*(v0(i,:)-y(j,:))+y(j,:)];
        end
    end
    y=v;
end


%hold off
%plot3(y(:,1),y(:,2),y(:,3),'.')

hold off
hold on
for n=1:1:max(size(y))/4;
    
plot3([y(4*n,1); y(4*n-3:4*n-2,1); y(4*n,1); y(4*n,1); y(4*n-1,1); y(4*n-2,1)],[y(4*n,2); y(4*n-3:4*n-2,2); y(4*n,2); y(4*n,2); y(4*n-1,2); y(4*n-2,2)],[y(4*n,3); y(4*n-3:4*n-2,3); y(4*n,3); y(4*n,3); y(4*n-1,3); y(4*n-2,3)])
plot3([y(4*n-3,1); y(4*n-1,1)], [y(4*n-3,2); y(4*n-1,2)],[y(4*n-3,3); y(4*n-1,3)])

end