function [ X, Y, R ] = fractal_feto( N )
% [ X, Y, R ] = fractal_feto( N )
%
% exemplo de uso:
% [ X, Y, R ] = fractal_feto( 1e5 );
% figure, plot( X, Y, '.g', 'markersize', 1 )

X(N) = 0;
Y(N) = 0;
R(N) = 0;

for n = 1:N-1
    p = rand;
    if p<.85
        X(n+1) = 0.85*X(n) + 0.04*Y(n);
        Y(n+1) = -0.004*X(n) + 0.85*Y(n)+1.6;
        R(n+1) = 1;
    elseif p<(.07+.85)
        X(n+1) = -0.15*X(n) + 0.28*Y(n);
        Y(n+1) = 0.26*X(n) + 0.24*Y(n) + 0.44;
        R(n+1) = 2;
    elseif p<(.07+.07+.85)
        X(n+1) = 0.2*X(n) - 0.26*Y(n);
        Y(n+1) = 0.23*X(n) + 0.22*Y(n) + 1.6;
        R(n+1) = 3;
    else
        X(n+1) = 0;
        Y(n+1) = 0.16*Y(n);
        R(n+1) = 4;
    end
            
end