function [ x, y, r ] = gera_triangulo( N, p )
% [ x, y, r ] = gera_triangulo( N, p );
if nargin<2
    p = [ 1 1 1 ];
end
x = ones(N,1);
y = ones(N,1);
r = zeros(N,1);
for n = 1 : (N-1)
    R = gera_inteiro( p );
    r(n+1) = R;
    switch( R )
        case{1}
            x(n+1) = x(n) / 2;
            y(n+1) = y(n) / 2;
        case{2}
            x(n+1) = x(n)/2 + 1;
            y(n+1) = y(n) / 2;
        case{3}
            x(n+1) = x(n)/2 + 0.5;
            y(n+1) = y(n)/2 + 1;
    end
end
    