%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         6.gyakorlat         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Nemlin. din. rsz-ek alapjai %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        2014.11.05/06        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          Fraktálok     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all;clear all;clc;
% Sierpinsky háromszög
N=1000;
%a háromszög csúcsai, az algoritmus fix pontjai
P(1,1)=1;P(1,2)=1;P(1,3)=1;
P(2,1)=1000;P(2,2)=1;P(2,3)=1;
P(3,1)=500;P(3,2)=860;P(3,3)=500;
P(4,1)=1;P(4,2)=1;P(4,3)=1000;
P(5,1)=1000;P(5,2)=1;P(5,3)=1000;


figure;
title('Sierpinski piramis');
xlim([0 N])
ylim([0 N])
zlim([0 N])
iternum=1000000; %iterációszám
C=zeros(iternum,3); %ide kerülnek majd a háromszög pontjai

% gyak:
c= P(floor(rand*3)+1,:);
c=P(randi([1,3]),:);
hold on;
for sz=1:iternum
    r=randi([1,5]);
    c=[(c(1)+P(r,1))/2,(c(2)+P(r,2))/2, (c(3)+P(r,3))/2];
    C(sz,:)=c;
%     plot3(c(1),c(3),c(2),'.','MarkerSize',3);
%     xlabel(['Itertaion: ',num2str(sz)]);
%     pause(0.01);
end


plot3(C(:,1), C(:,3), C(:,2), '.', 'MarkerSize', 1);
view([45,45,30]);
axis vis3d;
for j=1:36
    view([j*10,45,30]);
    pause(0.05);
end
title('Sierpinski piramis');
xlabel(['Iteration: ', num2str(iternum)]);
