function pahulja(rez, iter)
% rez - broj tacaka
% iter - broj iteracija
% pahulja(10000, 5000)

pts = zeros(rez,2);
x = rand(1);
y = rand(1);
plot(x,y,'.')
hold on
for j = 1:rez+iter
        p = rand(1);
        if p < 1/4
            xn = 1/3*x;
            yn = 1/3*y;
            x = xn;
            y = yn;
            plot(xn,yn,'.b')
        elseif p < 1/2
            xn = 1/6*x-sqrt(3)/6*y+1/3;
            yn = sqrt(3)/6*x+1/6*y;
            x = xn;
            y = yn;
            plot(xn,yn,'.r')
        elseif p < 3/4
            xn = 1/6*x+sqrt(3)/6*y+1/2;
            yn = -sqrt(3)/6*x+1/6*y+sqrt(3)/6;
            x = xn;
            y = yn;
            plot(xn,yn,'.g')
        elseif p <= 1
            xn = 1/3*x+2/3;
            yn = 1/3*y;
            x = xn;
            y = yn;
            plot(xn,yn,'.k')
        end
    pts(j,1) = x;
    pts(j,2) = y;
end%j

xs = pts(iter:end,1);
ys = pts(iter:end,2);
%plot(xs,ys,'.g')
axis equal
