Pratiksha D.Laldas SE Computer A Roll No. 53 Exiperiment No: 05 Aim: Implementation of Polygon Filling Algorithm. 1. Boundary-Fill Algorithm Code
Pratiksha D.Laldas SE Computer A Roll No. 53 Exiperiment No: 05 Aim: Implementation of Polygon Filling Algorithm. 1. Boundary-Fill Algorithm Code
Pratiksha D.Laldas SE Computer A Roll No. 53 Exiperiment No: 05 Aim: Implementation of Polygon Filling Algorithm. 1. Boundary-Fill Algorithm Code
Laldas
SE Computer A
Roll No. 53
Exiperiment No : 05
Aim: Implementation of Polygon Filling Algorithm.
1. Boundary-Fill Algorithm
Code:
#include <graphics.h>
void boundaryFill4(int x, int y, int fill_color,int boundary_color)
{
if(getpixel(x, y) != boundary_color &&
getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill4(x + 1, y, fill_color, boundary_color);
boundaryFill4(x, y + 1, fill_color, boundary_color);
boundaryFill4(x - 1, y, fill_color, boundary_color);
boundaryFill4(x, y - 1, fill_color, boundary_color);
}
}
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int x = 250, y = 200, radius = 50;
circle(x, y, radius);
boundaryFill4(x, y, 6, 15);
delay(10000);
getch();
closegraph();
return 0;
}
Output:
2. Flood-Fill Algorithm
Code:
// program to fill polygon using floodfill
// algorithm
#include <graphics.h>
#include <stdio.h>
// flood fill algorithm
putpixel(x, y, new_col);
}
}
int main()
{
int x = 51;
int y = 51;
int oldcolor = 0;
getch();
return 0;
// program to fill polygon using floodfill
// algorithm
#include <graphics.h>
#include <stdio.h>
// flood fill algorithm
void flood(int x, int y, int new_col, int old_col)
{
putpixel(x, y, new_col);
}
}
int main()
{
int x = 51;
int y = 51;
int oldcolor = 0;
// call for fill rectangle
getch();
return 0;
#include <graphics.h>
#include <stdio.h>
void flood(int x, int y, int new_col, int old_col)
{
if (getpixel(x, y) == old_col) {
putpixel(x, y, new_col);
flood(x + 1, y, new_col, old_col);
flood(x - 1, y, new_col, old_col);
flood(x, y + 1, new_col, old_col);
flood(x, y - 1, new_col, old_col);
}
}
int main()
{
int gd, gm = DETECT;
initgraph(&gd, &gm, "");
int top, left, bottom, right;
top = left = 50;
bottom = right = 300;
rectangle(left, top, right, bottom);
int x = 51;
int y = 51;
int newcolor = 12;
int oldcolor = 0;
Conclusion:
Hence we have successfully studied and implemented Polygon Filling Algorithm.