Fill a delimited region with a color in a draw

Game Editor comments and discussion.

Fill a delimited region with a color in a draw

Postby elfdav » Thu Oct 04, 2012 9:37 am

Hey guys,

Do you know if there is a simple way to fill a delimited region with a selected color with just one click.
Just like mspaint and many other softwares does.

Just see the attached draw...

For those who know that, i'm looking for the FloodFill API equivalent in Windows world.

Thanks for your help, guys.

David
Attachments
Baleine.png
elfdav
 
Posts: 14
Joined: Sat Feb 14, 2009 4:18 pm
Score: 0 Give a positive score

Re: Fill a delimited region with a color in a draw

Postby skydereign » Thu Oct 04, 2012 4:48 pm

If you set up a giant array to hold the values for your canvas, than it is pretty easy with a recursive function (something like this).
Code: Select all
int canv[100][100][3];

void
fill (int x, int y, int r1, int g1, int b1, int r2, int g2, int b2)
{
    canv[y][x][0] = r2; // might also use setpen here if you want this to be what updates your canvas
    canv[y][x][1] = g2;
    canv[y][x][2] = b2;

    if(x+1<100 && canv[y][x+1][0]==r1 && canv[y][x+1][1]==g1 && canv[y][x+1][g]==b1)
    { // right
        fill(x+1, y, r1, g1, b1, r2, g2, b2);
    }
    if(x-1>=0 && canv[y][x-1][0]==r1 && canv[y][x-1][1]==g1 && canv[y][x-1][g]==b1)
    { // left
        fill(x-1, y, r1, g1, b1, r2, g2, b2);
    }
    if(y+1<100 && canv[y+1][x][0]==r1 && canv[y+1][x][1]==g1 && canv[y+1][x][g]==b1)
    { // down
        fill(x, y+1, r1, g1, b1, r2, g2, b2);
    }
    if(y-1>=0 && canv[y-1][x][0]==r1 && canv[y-1][x][1]==g1 && canv[y-1][x][g]==b1)
    { // up
        fill(x, y-1, r1, g1, b1, r2, g2, b2);
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Fill a delimited region with a color in a draw

Postby elfdav » Sat Oct 06, 2012 8:50 pm

Thanks Sky.
elfdav
 
Posts: 14
Joined: Sat Feb 14, 2009 4:18 pm
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest