function [ C, R ] = triangulo(N, Ps)
% [ C, R ] = triangulo(N, Ps)
%
% exemplo de uso:
% [ C, R ] = triangulo( 1e5 );
% figure, plot( C, '.k', 'markersize', 1 )

if nargin<2
    Ps = [ 1/3 1/3 1/3 ];
end

C(N) = 0;
R(N) = 0;
% C = zeros(N,1);
C(1) = rand + 1i*rand;
R(1) = 0;
for i=1:(N-1)
    R(i+1) = aleatorio_com_probabilidade( Ps );
    if R(i+1)==1
        C(i+1) = C(i)/2;
    elseif R(i+1)==2
        C(i+1) = C(i)/2 + 1;
    else
        C(i+1) = C(i)/2 + 0.5 + 1i;
    end
end

if nargout==0
    plot( C, '.k', 'markersize', 1 )
    clear C
end
