CG Exp.4
CG Exp.4
:
X. I. E.
Mahim, Mumbai
Date :
aEXIEXIENIEXIEXNIEXIEXIEXIEXXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIE
EXPEBIHENT 0 4+
Algorithm:
) Check if cuwsent piel Cx ,y) s the
bounda coloY r the F I coler.
CUseady one ot these then move on
next pixel otherwise proceed wj th
3) left,yight
check neighboumin pxel (top ottom,
of thu current pNe
These pixel3 havee co-ordunte
(ocy-)
4 For each nelghbouing pixels
f the nelhboumng pixel has Bame
oounday do nothing:
|oit neighbou ng pixel has Same
color ab fl coroYdo nothinq.
. DF the nevghbousunq pel nas a
diyepf cooY, eairsvely appy
bounday fulgoithn with same
Fil| co|0Y
X. I. E.
Mahim, Mumbai
Page No. :
Date:
JENIENIENIxIENIENIENIEXNIEKIEXIEXIENIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIBEXIEXIEXIEXIEXIEXIEXJEXIEXIEI
Advanttage'
i) Easy to unddctand and lmplerment
Ii) Eaby to yu ascbitoasy closed shapc
Disadvantag
;) RecUNbwe' Stak oveflow
ii) Bouunday dependny
) Flood fu Alqoruthm
a connCed egLem
Lth a specitied color.
Input
i)The taHget magt
i) Staung pixel co-Drcuna Hes (x>y)
ii) Replacement coLDY
Algoithmi
pkps
4) Check the stanang pixel (x,y) o
oithun the oundasof the mage
1f Ltoousrde then teemunate the
clgoithm
X. I. E. Page No. :
Mabim, Mumbai
Date :
INIENIEXIENINIEXEXIEXIEXIEXTEXEXIEXIEXIEXIEXIEXIEXEXIEXIEXIEXIEXEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIXIEXIEXIEXIE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void boundary_fill(int x,int y,int be,int fc)
{
int currentpixel;
currentpixel=getpixel(x,y); if(currentpixel!=bc&¤tpixel!=fc)
{
setcolor(fc);
putpixel(x,y,fc);
delay(2);
boundary_fill(x+1,y,fc,bc);
boundary_fill(x-1,y,fc,bc);
boundary_fill(x,y+1,fc,bc);
boundary_fill(x,y-1,fc,bc);
}
}
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
setcolor(WHITE);
rectangle(240,240,320,320); boundary_fil(280,280,WHITE,RED);
closegraph();
getch();
}
Output:
Experiment 4.2: Implement Flood fill algorithm\Yash
Vijay Singh \53
Input/code:-
#include<stdio.h>
#include<conio.h>
winclude<graphics.h>
#include<math.h>
void flood(int x,int y,int fc,int oc)
{
int currentpixel;
currentpixel=getpixel(x,y);
if(currentpixel==oc)
{
putpixel(x,y,fc);
delay(2);
flood(x+1,y,fc,oc);
flood(x-1,y,fc,oc);
flood(x,y+1,fc,oc);
flood(x,y-1,fc,oc);
}
}
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode," C:\\Turboc3\\BGI ");
rectangle(50,50,100,100);
flood(55,55,WHITE,0);
flood(55,55,GREEN,WHITE);
closegraph();
getch();}
Output: