Mon 21 Feb 2005 10:49:29 PM UTC, original submission:
/* Flood Fill Algo */
/* 4 point Implementaiton */
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
flood(seed_x, seed_y, foreground_col,background_col) {
if(getpixel(seed_x, seed_y) != background_col &&
getpixel(seed_x, seed_y) != foreground_col)
{
putpixel(seed_x, seed_y, foreground_col);
flood(seed_x + 1, seed_y, foreground_col, background_col);
flood(seed_x - 1, seed_y, foreground_col, background_col);
flood(seed_x, seed_y + 1, foreground_col, background_col);
flood(seed_x, seed_y - 1, foreground_col, background_col);
flood(seed_x + 1, seed_y + 1, foreground_col, background_col);
flood(seed_x - 1, seed_y - 1, foreground_col, background_col);
flood(seed_x + 1, seed_y - 1, foreground_col, background_col);
flood(seed_x - 1, seed_y + 1, foreground_col, background_col);
}
return 0;
}
main() {
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
rectangle(50,50,100,100);
flood(55,55,4,15);
getch();
closegraph();
return 0;
}
|