Simple GUI Notepad Using Ruby

GUI Notepad Using Ruby Code require 'tk' class Notepad def saveFile file = File.open("note", "w") ...

Saturday, April 2, 2016

Boundary Fill C Program Using graphics.h

Boundary Fill Algorithm

Unlike Flood Fill Algorithm, Boundary Fill Algorithm starts at a point inside a region and paint the interior outward toward the boundary. If the boundary is specified in a single color, the fill algorithm proceeds outward pixel by pixel until the boundary color is encountered. This method, called the boundary-fill algorithm.

Follow The Instructions To Successfully Run The Program In Dev-Cpp/CodeBlock:

Whenever you #include <graphics.h> in a program, you must instruct the linker to 
link in certain libraries. The command to do so from Dev-C++ is Alt-P. Choose the 
Parameters tab from the pop-up window and type the following into the Linker area:

-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32

Code

#include <stdio.h>
#include <graphics.h>

/* fc = fill color and bc = boundary color */
void boundaryfill(int x, int y, int fc, int bc)
{
    int c = getpixel(x, y);
    if (c != fc && c != bc) {
        putpixel(x, y, fc);
        boundaryfill(x, y + 1, fc, bc);
        boundaryfill(x, y - 1, fc, bc);
        boundaryfill(x - 1, y, fc, bc);
        boundaryfill(x + 1, y, fc, bc);
    }
}

int main()
{
    int arr[] = {10, 10, 100,10, 10, 100, 10, 10};
    initwindow(300,300,"BoundaryFill");
    drawpoly(4, arr);
    
    delay(3000);
    
    boundaryfill(40, 40, 4, 15);
    
    while(!kbhit());
    
    return 0;
}

Output