CGR 5

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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