Colouring in pascal/C

Asked

Viewed 138 times

0

I have the following coloring code of regions using queue in Pascal:

program coloracao;
uses crt, filas;
const dim = 5;
type imagem = array [0...dim+1, 0...dim+1] of integer;
const I: imagem = ((-1, -1, -1, -1, -1, -1, -1),
                   (-1,  2,  1,  1,  3,  3, -1),
                   (-1,  1,  3,  3,  2,  3, -1),
                   (-1,  3,  2,  2,  2,  3, -1),
                   (-1,  3,  2,  3,  2,  3, -1),
                   (-1,  3,  3,  2,  3,  3, -1), 
                   (-1, -1, -1, -1, -1, -1, -1));

procedure exiba (var I: imagem);
var x, y: integer;
begin
    for x:=1 to dim do
        begin
            for y:=1 to dim do
                begin
                    textcolor(I[x,y]);
                        write (I[x,y]);
                end;
            writeln;
        end;
end;


procedure insf (var I: imagem; x,y,n:integer; var F: fila);
begin
    I[x,y]:=n;
    enfileira (x,F);
    enfileira (y,F):
end;

procedure emf (var x, y:integer; var F: fila)
begin
    x:=desenfileira(F);
    y:=desenfileira(F);
end;

procedure colorir (var I: imagem; x,y,n: integer);
var F: fila;
    a: integer;
begin
    iniciaf(F);
    a:=I[x,y];
    insf(I,x,y,n,F);
    while not vaziaf(F) do
        begin 
        remf (x,y,F);
        if I[x-1,y]=a then insf (I, x-1, y, n, F);
        if I[x,y+1]=a then insf (I, x, y+1, n, F);
        if I[x+1,y]=a then insf (I, x+1, y, n, F);
        if I[x,y-1]=a then insf (I, x, y-1, n, F);
        end;
end;

begin
    clrscr;
    exiba(I);
    readln;
    colorir(I,3,3,1);
    exiba(I);
    readln;
end.

My question is: What mechanism would I use to color in C, following this scheme of coloring an matrix?

  • 1

    Floodfill? http://en.wikipedia.org/wiki/Flood_fill

  • I don’t get it. It wouldn’t just be a matter of translating the code you have for C?

  • Yes, but I didn’t know how to translate this part of coloring in c

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.