0% found this document useful (0 votes)
44 views4 pages

CGR 5

The document describes a flood fill algorithm to fill a polygon on a computer graphics display. It explains that the algorithm starts with a seed pixel and examines neighboring pixels, replacing the interior color with a new color. It then provides pseudocode steps for the algorithm, including drawing a rectangle polygon, calling the flood fill function, and recursively filling neighboring pixels if they match the interior color. A flowchart and C program code implementing the algorithm are also included.

Uploaded by

omkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

CGR 5

The document describes a flood fill algorithm to fill a polygon on a computer graphics display. It explains that the algorithm starts with a seed pixel and examines neighboring pixels, replacing the interior color with a new color. It then provides pseudocode steps for the algorithm, including drawing a rectangle polygon, calling the flood fill function, and recursively filling neighboring pixels if they match the interior color. A flowchart and C program code implementing the algorithm are also included.

Uploaded by

omkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Subject: Computer Graphics (22318) Omkar Dorugade

Practical no 5
Aim: Program to fill Polygon.

Course Outcome: Implement standard algorithms to draw various graphics objects using C.

Practical Outcome: Write a program to fill Polygon using Flood fill algorithm.

Theory:

In Flood fill algorithm we start with some seed and examine the neighbouring pixels, however pixels are
checked for a specified interior colour instead of boundary colour and is replaced by a new colour. It can
be done by using 4 connected or 8 connected region method.

Algorithm:
Step 1. Start  

Step 2. Declare variables gd, gm, 2,4, fillcolor, default color.

Step 3. Draw a polygon. Eg. rectangle (200, 200, 200, 200).

Step 4. Call flood fill function by passing coordinate values of polygon. Eg, flood(219,
205).

Step 5. Run following block of code

If(getpixel (x,y)!= RED)

Putpixel (x, y, RED);

F_fill_fun (x+1, y);

F_fill_fun (x, y+1);

F_fill_fun (x-1, y);

F_fill_fun (x, y-1);

Step 6: End
Subject: Computer Graphics (22318) Omkar Dorugade
Practical no 5
Flow Chart:

Start

Declare variable gd, gm, x, y

Draw Polygon rectangle (200, 200, 200, 200)

Call f_fill_fun(intx, inty)

If
True False
(getpixel(x,y)
!=RED)

Putpixel (x, y, RED);

F_fill_fun (x+1, y);

F_fill_fun (x, y+1);

F_fill_fun (x-1, y);

F_fill_fun (x, y-1);

Stop
Subject: Computer Graphics (22318) Omkar Dorugade
Practical no 5
C Program Code:

#include <stdio.h>

#include <conio.h>

#include <graphics.h>

void f-fill-run (int, int);

void main ()

int gd = DETECT, gm, dd;

initgraph (&gd, &gm, "C:\UTC 1 BGI");

setcolour (RED);

rectangle (200,200,220,220);

F fill Fun (219,205);

getch ();

closegraph();

void f_fill_fun (inta, int y) 

If (getpixel x,y)!=RED)

f_fill_fun (x+1, y);

f_fill_fun (x, y+1);

f_fill_fun (x-1, y);

f_fill_fun (x, y-1);

*************************************Output******************************************
Subject: Computer Graphics (22318) Omkar Dorugade
Practical no 5

You might also like