You are on page 1of 14

UNI

TII
FI
VEMARKSANDTENMARKS
1.ExplainDDA-li
nedrawingalgori
thm.( APR12,APR13, NOV13,NOV16)
Digit
al Di
ff
erent
ial
Analyzer
-DDAwasamechani caldevi
cef ornumerical
solut
ionofdi
ff
erent
ial
equati
ons
-Liney =mx+bsati
sfi
esdi f
fer
entialequat
ionwithtwoendpoint
s(x1,
y1)
,(x2,
y2)
.
dy /dx=m =Δy /Δx=y 2-y1/
x2-x1

Forl i
newi thsl opemagni tude| m|<1, Δxcanbesetpr oport
ionaltoasmal l
hori
zont aldef l
ect i
onv oltageandt hecor respondi ngv erticaldefl
ectioni st hen
proporti
onal toΔy .
Slopemagni tude| m| >1,Δycanbesetpr opor tionalt oasmal lv er t
ical
defl
ection v ol tage wi tht he cor r
espondi ng hor i
zont aldef l
ecti
on voltage set
proporti
onal toΔx .
Slopemagni tude| m| =1,Δx=Δyandt hehor i
zont alandv ert
icaldef l
ect i
on
volt
agesar eequal .
DDAAl gor i
thm:
Step1: Gett hei nputoft woendpoi nts( X0,Y0)and( X1, Y1) .
Step2: Cal cul atet hedi fferencebet weent woendpoi nts.
Step3:Basedont hecal culateddi fferencei nstep- 2,y ouneedt oident if
yt he
numberofst epst oputpi xel.Ifdx>dy ,theny ouneedmor estepsinxcoor dinate;
otherwisei nycoor dinat e.
Step4: Cal cul atet hei ncr ementi nxcoor dinat eandycoor dinate.
Step 5:Putt he pi xelby successf ull
yi ncr ement ing x and y coor dinates
accordingl yandcompl etest hedr awi ngoft hel ine.
procedur el i
neDDA( x0, y 0,
x1, y1:integer);
var
dx, dy,st eps,k: integer ;
xinc, yinc, x,
y:int eger ;
begin
dx: =x1-x0
dy: =y 1-y 0
i
f (absol ute(dx)>absol ute(dy))thenst eps=absol ut e(dx)
;
elsest eps=absol ut e(dy);
xinc=dx/( float )st eps;
yinc=dy/( float )st eps;
x:=x0;
y:=y 0;
set Pixel (round( x),round( y )
,1);
fork: =1t ostepsdo
begi n
x: =x+xi nc;
y: =y+y i
nc;
set Pi
xel (round( x),r
ound( y )
,1);
end
1
end

TheDDAal gori
thm isf astert hanthedi r
ectuseoft heli
neequat i
onsi nce
i
tcalcul atespointsont hel inewithoutanyf l
oatingpointmulti
pli
cati
on.
Advant agesofDDAAl gorithm
1.I tist he simpl estal gorithm and i tdoes notr equir
e specialskil
l
sf or
i
mpl ement at
ion.
2.Itisaf astermet hodf orcal culatingpixelpositi
onst hanthedi r
ectuseof
equationy=mx+b.I teliminatest hemul ti
pli
cati
oni ntheequationbymaki ng
useofr astercharacteristi
cs,sot hatappr opr
iateincrementsareappliedi
nt hex
orvdirect iontofindthepi xel positi
onsal ongthelinepath.
Disadvant agesofDDAAl gor i
thm
1.Floatingpoi ntarit
hmet icinDDAal gori
thm issti
llti
me-consuming.
2.Theal gori
thm isorientationdependent .Henceendpoi ntaccuracyispoor.

2.Wr i
tethestepsinBresenham’ sli
nedr awi ngal gorithm.( APR13, NOV12, NOV14,
APR15)
Anaccur at
eandef fi
cientrasterl i
negener atingal gorithm dev elopedby
Bresenham, t
hatusesonl yi
ncr emental i
nt egercal culations.
Inaddit
ion,Bresenham’ sli
neal gor i
thm canbeadapt edt odi splaycir
cles
andothercurves.
Toi l
lustrateBr esenham' sappr oach,we-
fir
stconsi dert hescan- conv ersionpr ocessfor
li
neswi thposi tivesl opelesst han1.
Pi xelposi tions al ong a l i
ne pat h are
thendet ermi nedbysampl i
ngatuni txinter
vals.
St arti
ngf rom t heleftendpoi nt(x0,
y0)of
a gi ven l ine,we st ep to each successi ve
column( xposi ti
on)andpl ott hepi xelwhose
scan- l
ineyv aluei scl osesttot helinepat h.

Br
esenham’ sl
ineDrawi ngAlgorithm for|m| <1
Step1:Inputthet wolineendpoi ntsandst oret
hel
eftendpointin(x0,
y0)
Step2:Load( x0,y0)i
ntof ramebuf fer,ie.Plott
hef
irstpoi
nt.
Step3:Calculatetheconst antsΔx, Δy ,2Δyandobtainthestart
ingval
ue
forthedecisi
onpar amet eras
P0=2Δy -
Δx
Step4:Ateachxkal ongt heli
ne, st
artingatk=0performthef ol
l
owingtest
I
f Pk<0, t
henextpoi ntt oplotis(xk+1,yk)and
Pk+1=Pk+2Δy
Otherwise,
thenextpoi ntt oplotis(xk+1, y
k+1)and
Pk+1=Pk+2Δy-2Δx5.
Step5:Perform step4Δxt imes.

procedureli
neBres(xa,
ya,
xb,yb:i
nteger
);
var
dx,
dy,x,
y,
pxend: i
nteger;
begin
dx:=abs(xa–xb) ;
dy:=abs(ya–y b);
p:
=2*dy-dx;
i
fxa>xbt hen
2
begi n
x:=xb;
y :
=y b;
xend: =xa;
end
el
se
begi n
x:=xa;
y :
=y a;
xend: =xb;
end
set Pixel (
x,y,
1);
whi l
ex<xenddo
begin
x:=x +1;
i
fp<0t henp:=p+2*dy
else
begi n
y:
=y +1;
p:=p+2* (dy
-dx)
end
setPi xel(
x,y,
1);
end
end

Advantages
Al
gorit
hm isFast
Usesonlyint
egercal
cul
ati
ons
Di
sadvantages
I
tismeantonlyforbasi
cli
nedrawi
ng.

3.Wri
tet
hestepsi
nMi dpoi
ntCi
rcl
eAl
gor
it
hm.(
NOV13,APR14,APR15,APR16,
NOV11,APR12)
Pr
oper
ti
esofCir
cle:

1.Acircl
ei sdefinedasasetofpoi nt
st hatareal
lthegiv
endi st
ance(xc,
yc)
.
2.This distance rel
ati
onshi pis expressed byt he pythagor
ean theorem in
Cart
esi ancoordinat
esas
2 2 2
(
x–xc) +(y–y c) =r (1)
3.Tocal culatethepositionofpoi nt
sonaci rcl
ealongthexaxi sinunitsteps
fr
om xc- rtoxc+randcal culat
ingthecor r
espondingyv al
uesateachposi t
ion
as
3
2 2 1/
y=y c+( r –( xc–x) )2 (2)
Spaci ngbet weenpl ottedpi xel si snotuni form.
4.To el i
mi natet heunequalspaci ng i st o cal cul atepoi nt sal ong t heci rcl
e
boundar yusingpol arcoor dinat esrandθ.
x=xc+r cosθand y=y c+r sinθ
5.Sett heangul arst epsi zeat1/ r.Thispl ot spi xel posi tionst hatar e
approxi matelyoneuni tapar t.Theshapeoft heci r clei ssi milari neach
quadr ant.
Todet ermi net hecur v eposi t
ionsi nt hef irst
quadr ant ,togener atet heci rclesect ioni nt he
secondquadr antoft hexypl anesy mmet ri
cwi th
respectt otheyaxi sandci rcl esect ioni nt het hir
d
andf our thquadr ant scanbeobt ained.
Ci r
clesect ionsi nadj acentoct antswi thi none
quadr antar esy mmet r
icwi thr espectt ot he45
degr eelinedi v idingt het wooct ants.Wher eapoi nt
atposi tion( x,y )onaone- eightci rclesect oris
mappedi ntot hesev enci r
clepoi nt sint heot her
octantsoft hexypl ane.
Midpointci rcl
eAl gorithm
Cir clepat hateachst epf oragi v enr adi usrand
scr een cent r
e posi tion ( xc, y c)t o cal culat e pi xel
posi ti
ons ar ound a ci rcle pat h cent ered att he
coor dinat eposi ti
onbyaddi ngxct oxandy ct oy .
Toappl yt hemi dpoi ntmet hodwedef inea
circl efunct ionas
)=x2+y 2 2
fcircle( x,y -
r
Anypoi nt( x,
y )ont heboundar yoft heci rcl
e
wit
hr adiusrsat isfiest heequat ionf ci r
cle( x,y )
=0.
Ift hepointi si nt hei nter ioroft heci rcle,t heci rclef unct ioni snegat ive.
Andi ft
hepoi ntisout sidet heci rcl ethe, circlef unct ioni sposi ti
ve
f
cir
cle(
x,y
)<0,
if(
x,y
)isinsidethecir
cleboundary,
=0,if(
x,y)isonthecircl
eboundary,
>0,i
f(x,y
)i sout
sidethecir
cleboundar
y.
Thet
estsi
ntheaboveeqnar
eper
formedforthemidpointbet
weenpi
xels
nearthecir
clepat
hateachsampli
ngstep.Thecir
clefunct
ionisthedeci
sion
parameteri
nthemidpoi
ntal
gor
it
hm.

Algori
thm
Step1:I nputradi
usrandci rcl
ecent re( xc,yc)andobt ainthef i
rstpoi
ntonthe
cir
cumf erenceoftheci r
clecent redont heor iginas( x0,y
0)=( 0,
r)
Step2: Calculat
et heinit
ialvalueoft hedeci sionparamet eras
P0=( 5/4)-r
Step 3:Ateachx kposi t
ion,st arti
ngatk=0,per formt hef ol
l
owi ngtest.I
fPk<0
thenextpoi ntal
ongt hecirclecent redon( 0,
0)i s(xk+1,yk)and
Pk+1=Pk+2xk+1+1
Otherwisethenex tpointalongt heci rcleis(xk+1, yk-
1)and
Pk+1=Pk+2xk+1+1- 2yk+1
Wher e2xk+1=2xk+2and2y k+1=2y k-2
Step4: Det er
minesy mmet r
ypoi ntsi ntheot hersev enoct ant
s.
Step 5:Mov eeachcal culatedpi xelposi ti
on( x,
y)ont othecircularpat
hcentr
ed
at(xc,
yc)andpl otthecoor dinatev alues.x=x+xc, y=y +yc

4
St
ep6:
Repeatst
ep3t
hrough5unt
ilx>=y
.

procedur ecir
clemidpoi nt(
xcen, ycen,
radi
us:
int
eger
);
var
p,x,y: integer ;
procedur eplotpoints;
begi n
set Pixel(
xcen+x,y cen+y ,1);
set Pixel(
xcen-x,ycen+y ,1);
set Pixel(
xcen+x,y cen-y,1);
set Pixel(
xcen-x,ycen-y,1) ;
set Pixel(
xcen+y ,
y cen+x, 1);
set Pixel(
xcen-y,y
cen+x, 1);
set Pixel(
xcen+y ,
y cen-x,1);
set Pixel(
xcen-y,y
cen- x,1) ;
end;
begi n
x:=0;
y:=r adi us;
plot poi nts;
p:=1- radius;
whi lex<ydo
begi n
ifp<0t hen
x:=x+1;
el se
begi n
x: =x+1;
y :=y -
1;
end
i
fp<0t hen
p: =p+2*x+1
else
p: =p+2*(x-
y)+1;
plot poi nts;
end;
end;

4.Explai
nbr i
eflyaboutl ineat t
ri
but es.(APR13,APR14, APR16, NOV15)
Anypar amet ert hataffectsthewayapr imi
ti
v eistobedi spl
ayedis
refer
redt oasanat t
ributepar amet er.Exampl
eatt
ributeparamet er
sarecolor
,
sizeetc.Al inedr awingf unctionf orexamplecoul
dcont ai
nparamet ertoset
color,widthandot herpr operties.
1.LineAt tri
butes
2.Curv eAt t
ributes
3.ColorandGr ayscaleLev els
4.AreaFi llAttr
ibutes
5.Char acterAt tr
ibutes
6.Bundl edAt tri
butes
LineAt tr
ibutes
 
   
 Basicat t
ributesofast rai
ghtl inesegmentarei
tst y
pe,it
swi dth,andit
scolor
.

5
Insomegr aphi cspackages, li
nescanal sobedi splay edusi ngsel ectedpenor
brushopt i
ons
*Li neTy pe
*Li neWi dth
*PenandBr ushOpt i
ons
*Li neCol or
Linet y pe
 
   
 Possi blesel ect ionofl i
net ypeat t
ribut eincludessol i
dl ines, dashedl inesand
dot tedl ines.Tosetl inet y peat t
ri
butesi naPHI GSappl i
cat ionpr ogram, auser
i
nv okest hef unct ion
 
   
    
   
    
   
   
  
     
    
   
   
   
  set Linetype( lt
)
 
   
 Wher epar amet erl tisassi gnedaposi ti
vei ntegerv alueof1, 2, 3or4t o
gener atel inest hatar esol id,dashed, dashdot tedr espect ivel
y .Ot herv aluesf or
l
inet ypepar amet eri tcoul dbeusedt odi splayv ari
at i
onsi ndot -dashpat ter ns.
Linewi dt h
 
   
 Impl ement at ionofl inewi dthopt i
ondependsont hecapabi l
itiesoft heout put
dev icet osett hel i
newi dt hat tri
butes.
 
   
    
   
    
   
   
  
     
    
   
set Linewi dthScaleFact or(lw)
 
   
 Linewi dthpar amet erl wi sassi gnedaposi tivenumbert oindi catether elativ
e
widt hofl inet obedi splay ed.Av al
ueof1speci fi
esast andar dwi dthli
ne.Auser
coul dsetl wt oav alueof0. 5t oplotal inewhosewi dthi shalft hatoft he
standar dl ine.Val uesgr eat ert han1pr oducel inest hickert hant hest andar d.
LineCap
 
   
 Wecanadj ustt heshapeoft helineendst ogi v
et hem abet terappear anceby
addi ngl i
necaps.
Ther ear et hreet y pesofl inecap.Theyar e
*But tcap
*Roundcap
*Pr oject ingsquar ecap
But tcapobt ai nedbyadj ust i
ngt heendposi t
ionsoft hecomponentpar allellines
sot hatt het hi ckl inei sdi splay edwi thsquar eendst hatar eper pendi culart ot he
l
inepat h.
Roundcapobt ainedbyaddi ngaf i
ll
edsemi circlet oeachbut tcap.Theci rcul ar
arcsar ecent er edont hel ineendpoi ntsandhav eadi amet erequal t
ot hel ine
thickness.
Proj ectingsquar ecapext endt hel i
neandaddbut tcapst hatar eposi t
ionedone-
halfoft hel i
newi dt hbey ondt hespeci f
iedendpoi nts.

Thr
eepossibl
emet
hodsf
orsmoot
hlyj
oini
ngt
wol
i
nesegment
s:
*Mit
terJoi
n
*RoundJoin
*BevelJoi
n

6
Ami terj
oinaccompl ishedbyextendingtheouterboundari
esofeachofthetwo
l
inesuntiltheymeet .
Aroundj oinisproducedbycappi ngtheconnecti
onbet weenthetwosegments
withacircularboundar ywhosediameterisequaltothewidth.
Abev elj
oinisgenerat edbydispl
ayingtheli
nesegmentwi thbutcapsandfi
l
li
ng
i
nt r
iangulargapwher et hesegmentsmeet .

PenandBr ushOpti
ons
Withsomepackages, l
i
nescanbedisplayedwit
hpenorbrushsel
ect
ions.
Optionsi
nthiscat
egoryincl
udeshape,
size,andpat
ter
n.Somepossi
blepenor
brushshapesaregiv
eni nFi
gur
e

Li
necol or
 
  
  Apolyli
ner outi
nedi splaysalineint hecurrentcolorbyset
ti
ngthi
scolorv
alue
i
nt heframebuf feratpixel l
ocati
onsal ongt helinepathusi
ngthesetpi
xel
procedure.
Wesett helinecolorv alueinPHlGSwi ththef unct
ion
 
  
   
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 setPolyl
ineColourIndex(lc)
 
  
  Nonnegativeint
egerv al
ues,correspondingt oall
owedcolorchoi
ces,
are
assignedtot heli
necol orpar ameterlc.

Curveatt
ri
butes
 
  
  
Parametersf
orcurveatt
ribut
earesameasthoseforl
inesegments.Cur
ves
di
splayedwit
hv ar
yingcol
ors,wi
dths,
dot–dashpatt
ernsandavai
lablepenor
br
ushopt i
ons.

Exampl e:Var i
ousl ineattr
ibutecommandsi
nanappl
i
cat
ionspr
ogr
am i
sgi
venby
thefoll
owi ngsequenceofst at
ement
s
setLi
nety pe(2);
setLi
newi dthScaleFact or
(2);
setPolyl
ineCol ourIndex(5);
polyl
ine(n1,wcpoi nts1);
setPolyl
ineCol orI
index(6);
polyli
ne( n2, wcpoi nts2)
;

7
 
  
  
Thisprogr
am segmentwoul
ddispl
aytwof i
gures,
drawnwit
hdoubl
e-wi
de
dashedli
nes.Thefir
sti
sdi
spl
ayedinacolorcorr
espondi
ngtocode5,
andthe
secondincolor6.

5.Whatar eallthechar act erat tr i


but es?Descr i
be.(NOV11,NOV12,NOV14,NOV
15)
CharacterAt tri
but es
 
  
  
Theappear anceofdi spl ay edchar acteriscont rol
ledbyat t
ri
butessuchasf ont,
si
ze, colorandor ientat i
on.At t ri
but escanbesetbot hf orenti
rechar act
erstri
ngs
(t
ext)andf orindiv i
dual char act ersdef inedasmar kersymbols.
TextAt tri
butes
 
  
  
Thechoi ceoff ontort ypef acei ssetofchar acterswithapar ti
culardesign
sty
leascour ier,Hel vetica, ti
mesr oman, andv ar
ioussy mbol groups.
 
  
  
Thechar act ersinasel ect edf ontal sobedi splayedwi t
hstyles.(soli
d,dott
ed,
double)inbol df acei ni talics, andi nout l
ineorshadowst yl
es.
 
  
  
Apar ti
cularf ontandassoci atedst vl
ei sselectedinaPHI GSpr ogr am by
sett
ingan
i
ntegercodef ort het extf ontpar amet ertfinthef uncti
on
 
  
  
  
    
  
  
  
  
   
  
  
     
  
  
    
   set Text Font( tf)
Controloft extcol or( ori nt ensi t
y)i smanagedf r
om anappl i
cati
onpr ogram with
 
  
  
  
    
  
  
  
  
   
  
  
    
  
  
  
   set Text Col our I
ndex( tc)
Wher etextcol orpar amet ert cspeci fi
esanal l
owabl ecolorcode.
 
  
  
Textsi zecanbeadj ust edwi thoutchangi ngthewi dthtoheightrat i
oof
characterswi th
 
  
  
  
    
  
  
  
  
   
  
  
    
  
  
  
   set Char acter Height(ch)

Parameterchisassi gnedar ealval


uegr eat
erthan0tosetthecoor
dinat
e
heightofcapit
allet
ters.Thewi dthonlyoftextcanbesetwi t
hfuncti
on.
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 setCharact
erExpansionFactor(
cw)
 
  
  
Wher ethecharact erwidthparametercwi ssettoaposi
ti
vereal
value
thatscal
esthebodywi dthofchar act
er

Spaci
ngbet weenchar actersi
scontrol
ledsepar
atel
ywi
th
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
setChar
acter
Spacing(cs)
Wherethechar acter
-spacingpar
amet ercscanheassi
gnedanyr
eal
val
ue

8
 
  
  
Theor i
entati
onf oradi splayedcharacterstri
ngissetaccordingtothe
di
recti
onoft hechar acterupv ector
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
   
 setCharacter
UpVect or(upvect
)
 
  
  
Paramet erupvectint hisfuncti
onisassi gnedtwov al
uesthatspecifyt
hex
andyv ect
orcomponent s.Forexampl e,
wi t
hupv ect=(1,1)
,thedirect
ionoft
he
upvectoris45oandt extwoul dbedi spl
ayedasshowni nFigure.

Toarrangechar act
erstri
ngsv er
ti
call
yorhori
zont
all
y
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 setText
Path(tp)
canbeassi gnedthev al
ue:right,l
eft
,up,ordown

 
  
  
Anotherhandyat t
ri
butef orchar act
erst ri
ngsi salignment .Thisat t
ri
bute
speci
fi
eshowt extistobeposi t
ionedwi threspectt ot he$tartcoordinat
es.
Ali
gnmentat t
ributesaresetwi t
h
 
  
  
  
  
  
  
  
  
   
  
  
   
   
  
  
  
  
  
  
  
  
  
  
setText Al
ignment( h,v)
wherepar amet ershandvcont r
ol horizontalandv erticalal
ignment .Horizontal
ali
gnmenti ssetbyassi gni
nghav alueofl eft
, center
, orri
ght.Ver t
icalal
ignment
i
ssetbyassi gningvav al
ueoft op, cap, half
,baseorbot tom.
Apr ecisionspecifi
cationf ortextdisplayi sgivenwi t
h
  
  
    
  
  
   
   
  
  
  
  
  
  
  
  
  
  
  
  
  
   
  
 setTextPrecision( tpr
)
tpri sassi gnedoneofv aluesstr i
ng,charorst roke.
MarkerAtt
ributes
  
  
 Amar kersymbol isasi nglechar acterthatcanhedi splayedindifferent
9
colorsandi ndi fferentsi zes.Mar kerat tri
but esar eimpl ement edbypr ocedur es
thatloadt hechosenchar acterintot her asteratt hedef i
nedposi ti
onswi tht he
specifi
edcol orandsi ze.Wesel ectapar ti
cul archar actertobet hemar ker
symbol wi th
  
   
  
  
  
    
  
   
  
  
     
  
   
   
   
  
  
  
  
  set Mar ker Type( mt )
wher emar kert y pepar amet ermti ssett oani ntegercode.Ty pi
calcodes
formar kertypear ethei nteger s1t hr ough5, specifying,respectively,adot( .
)a
verti
calcross( +),anast erisk( *)
,aci r
cl e(o) ,andadi agonal cr
oss( X).
Wesett hemar kersi zewi th
 
   
  
  
  
  
  
   
  
  
  
    
  
   
  
  
     
  
  setMar ker SizeScal eFact or( ms)
wi t
hpar amet ermar kersizemsassi gnedaposi ti
venumber .Thisscal ing
paramet erisappl i
edt ot henomi nal sizef ort hepar ticularmar kersy mbol chosen.
Valuesgr eatert han1pr oducechar act erenl argement ;valueslesst han1r educe
themar kersi ze.
Mar kercolori sspeci fiedwi th
 
   
  
  
  
  
  
   
  
  
  
    
  
   
  
  
     
  
 set Polymar ker Col our I
ndex( mc)
  
   
Asel ect edcol orcodepar amet ermci sst oredi nthecur rentattr
ibut e
l
istandusedt odi splaysubsequent lyspeci fi
edmar kerpr imiti
ves.

6.Wr
it
eshor
tnot
eson:
Flood–f
il
lal
gor
it
hm.(
NOV15)
Anareabor deredbysev er
al diff
erentcolorregion.Wecanpai ntsuchaar eaby
repl
acingaspeci f
iedint eriorcolorinsteadofsear chingf oraboundarycolorvalue.This
approachiscal l
edf loodf ill
.
 St artfrom speci fi
edinteriorpoint(x,
y )
.
 Reassi gnal l pixelvaluest hatarecurrentlysettoagiv eni
nter
iorcolorwi th
desiredf i
ll
col or .
 Use4- connect edor8- connect edregionunt i
lalli
nter
iorpoi
ntsbeingr eplaced.
procedureFl oodFill4(x,y,f
il
lcol
or,oldcolor
:i
nteger)
begin
i
fget Pi
xel(x,y)=ol dCol orthen
begi n
10
setPixel
(x,
y,
fi
ll
col
or);
FloodFil
l4(
x+1,y,
fil
lcol
or,oldCol or)
;
FloodFi
ll
4(x-
1,y,fi
ll
color,oldColor)
;
FloodFi
ll
4(x,
y+1, f
il
lcolor
, oldColor
);
FloodFi
ll
4(x,
y-1,fi
ll
color,oldColor)
;
end
end

7.Descr i
bei ndet ail,Boundary-Fill
Algorit
hm.( APR14, NOV16)
Thi
sal gorithm pi cksapoi ntinsideanobj ectandstartstofillunt i
lithit
st he
boundar yoft heobj ect .Ift
heboundar yisspecif
iedinasi nglecolor ,t
hef il
l al
gorit
hm
proceedsout wardpi xel bypixelunt i
ltheboundar ycolorencounter ed.Thismet hod
iscalledboundar yf i
l
l algori
thm.
Int hi
salgor i
thm, weassumet hatcoloroftheboundar yissamef ortheent ir
e
object.Theboundar yf il
lalgorit
hm canbei mplement edby4- connectedpi xel
sor8-
connect edpixels.
4-Connect edPol ygon
Inthist echni que4-connect edpixel
sar eusedasshowni nthef igur
e.We
areput tingt hepixelsabov e,bel
ow, totheright,andtot hel eftsideoft he
currentpi xelsandt hisprocesswi ll
cont i
nueunt il
wef i
ndaboundar ywi t
h
diff
erentcol or.

Algor
it
hm
Step1−Init
ial
i
zet hev al
ueofpoi nt(x,
y),
fi
ll
,boundary.
Step2−Definetheboundar yvaluesofthepol ygon.
Step3−Checki fthecurrentpointisofdefaultcolor,t
henr epeatt
hesteps4and5t
il
l
theboundar
ypixelsreached.
Step4−Changet hedef aul
tcolorwi t
hthef i
llcoloratthepoint.
Step5−Recursivelyfoll
owthepr ocedurewi t
hf ourneighborhoodpoi
nts.
Step6–Exit
procedureboundar yFi
ll
4(x,
y,f
il
l,boundary:
i
nteger
)
var
cur r
ent:
integer
begin
curr
ent=get Pi
xel(x
,y);
i
f(curr
ent <>boundar y
)and( current
<>fil
l)t
hen
begin
set Pi
xel(
x,y,
fil
l);
boundar yFi
ll4(x+1,y,fi
ll
,boundary);
boundar yFi
ll
4(x-
1, y,
fil
l
,boundar y)
;
boundar yFi
ll
4(x,y+1,fi
ll
,boundary);
boundar yFi
ll
4(x,y-
1,fil
l
,boundar y)
;
end
end

Thereisaprobl
em wit
hthist
echni
que.Consi
derthecaseas
shownbelowwher ewetri
edtofi
ll
theenti
rer
egion.Here,
the
i
magei sfi
ll
edonlypar
ti
all
y.I
nsuchcases,4-
connectedpi
xel
s
techni
quecannotbeused.

8-
Connect
edPoly
gon
I
nthi
stechni
que8-connect
edpi
xel
sar
eusedasshowni
nthef
igur
e.Wear
eput
ti
ng
11
pi
xelsabov
e,below, r
ightandl
eftsi
deoft
hecur
rentpi
xel
saswewer
edoi
ngi
n4-
connect
edtechnique.

I
naddit
iontothi
s,wearealsoputt
ingpi
xel
sindiagonal
ssothat
ent
ir
eareaofthecur
rentpi
xel
iscov er
ed.Thi
sprocesswil
lcont
inue
unt
ilwefi
ndaboundarywit
hdiff
erentcol
or.

Algor
it
hm
Step1−Init
ial
i
zet hev al
ueofpoi nt(x,y
),fi
l
landboundar y.
Step2−Definetheboundar yvaluesoft hepolygon.
Step3−Checki fthecurrentpointisofdefaultcol
orthenrepeatt
hesteps4and5t
il
l
theboundar
ypixelsreached
Step4−Changet hedef aul
tcolorwi tht
hef i
l
lcolorattheseedpoint
.
Step5−Recursivelyfoll
owthepr ocedurewithfourneighbour
hoodpoints
Step6–Exit

8.Whatar einquiryfuncti
ons?Expl ain.( NOV15)
Currentsetti
ngsforat tr
ibut esandot herpar amet ersaswor kst
ati
ons
typesandst atusinthesy stem listscanber etri
ev edwi thinqui
ryfuncti
ons.
 
   
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 i
nqui r
ePol y l
i
neIndex(l ast li
)
 
   
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
   
  
  
  
    
  
  
   
 and
 
   
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 i
nqui r
eInteriorcCol ourIndex( l
astfc)
Copyt hecur r
entvaluesforl i
nei ndexandf il
lcolori ntoparameterlastl
iandlast
fc.
Thef oll
owingprogr am segmenti llust r
atesr eusingt hecur
rentli
netype
valueafterasetofl i
nesar edrawnwi thanewl i
net ype.
i
nqui reLinety pe(oldl
t )
;
set Linetype( newlt);
.
:
setLinetype( oldlt)
;

9.Whatar
ethei
mpor
tantf
eat
uresofGr
ayscal
eingr
aphi
cs?(
APR12,
NOV12)
COLORANDGRAYSCALELEVELS
Variouscol orandi ntensit
y-l
eveloptionscanbemadeav ail
abletoauser ,dependingon
thecapabi
liti
esanddesi gnobj ecti
vesofapar t
icularsystem.
Gener alpurposer aster-
scansy stemsusual l
yprov i
deawi derangeofcol ors,butrandom
-scanmonitorst y
picallyof f
eronlyaf ewcolorchoi ces,ifany.Col oropt i
onsarenumer i
call
y
codedwithv aluesr angingf r
om 0t hr
ought heposi ti
veinteger s.
ForCRTmoni t
ors,thesecolorcodesar et henconv ertedt ointensit
ylevelsett
ingsforthe
elect
ronbeams.Wi t hcolorplott
ers,t
hecodescoul dcontrolink-jetdepositsorpensel ect
ions.
Color-i
nformat ioncanbest or
edint hef r
amebuf feri
nt woway s:
 Wec anst orecolorcodesdi rectlyinthef ramebuf fer.
 Wec anputt hecol orcodesi nasepar atetabl eandusepi xelvaluesasan
i
ndexi
ntot
hist
abl
e.
Withthedirectst oragescheme, whenev erapar t
icularcol
orcodei sspeci f
iedinan
applicati
onprogram, thecor r
espondingbinar yvaluei splacedi ntheframebuf ferforeach-
componentpi xelintheout putpr i
miti
vestobedi splayedi nthatcolor.
Ami ni
mum numberofcol orscanbepr ov i
dedi ntheschemewi t
h3bi tsofst orageper
pixel
, asshowni nTabl e.Eachoft hethr
eebi tpositionsi susedt ocontroltheintensitylevel
(eit
heronorof f)ofthecor respondingelectr
onguni nanRGBmoni t
or.
Theleft
mostbi tcont rol
stheredgun, t
hemi ddlebitcont r
olsthegr eengun, andt he
ri
ghtmostbi tcontrol
st hebl uegun.
Addingmor ebi tsperpi xeltotheframebuf f
eri ncreasesthenumberofcol orchoices.
Wi t
h6bi tsperpixel,2bi tscanbeusedf oreachgun.Thi sal l
owsf ourdi
fferentint
ensi t
y
12
setti
ngsf oreachoft het hreecol orguns, andat ot alof64col orv al
uesar eav ailabl
ef oreach
screenpi xel.
Wi thar esol utionof1024by1024, af ull-
col or(24bitperpi xel)RGBsy stem needs3
megaby tesofst or agef orthef ramebuf fer .Colort ablesar eanal t
ernat emeansf orpr ovi
ding
extendedcol orcapabi liti
est oauserwi thoutr equir i
ngl argeframebuf fers.
Lower -
costper sonal comput ersy st ems, i
npar t
icular,
oft enusecol ort ablestor educe
frame-buf ferstor ager equi rement s.
(i
)COLORTABLES:
Apossi bleschemef orstori
ngcol orv aluesi nacol orl
ookupt abl e( orv ideolookupt abl
e),
wher eframe- buf ferv aluesar enowusedasi ndicesi ntot hecolort able.
Ineachpi xel canr eferenceanyoneoft he256t abl epositions, andeachent ryinthe
tableuses24bi tst ospeci fyanRGBcol or .Fort hecol orcode2081, acombi nationgr een-blue
colorisdi splayedf orpi xellocation(x, y).
Sy stemsempl oy i
ngt hispar t
icularl ookupt ablewoul dal l
owausert osel ectany256
colorsforsi mul taneousdi splayfrom apal ett
eofnear l
y17mi ll
ioncol or s.
Compar edt oaf ullcolorsy stem, thi sschemer educest henumberofsi multaneous
colorsthatcanbedi spl ayed, butitalsor educest hef r
amebuf ferst orager equi rement sto1
megaby te.
Somegr aphi cssy stemspr ov ide9bi tsperpi xelinthef r
amebuf fer,per mitt
ingausert o
select512col orst hatcoul dbeusedi neachdi splay .
Ausercansetcol or-t
ableentri
esinaPHI GSappl icati
onspr ogram wi
ththe
functi
on
 
   
  
  
  
  
  
  
  
  
  
  
  
  
setColourRepresentat
ion(ws, ci
,colorptr)
Paramet erwsi denti
fi
esthewor kstat
ionout putdev i
ce;paramet
erci
specif
iesthecol orindex,whichisthecolor-
tablepositionnumber( 0to255)and
parametercolor pt
rpointstoat ri
oofRGBcol orvalues( r
,g,b)eachspecif
iedi
n
therangef r
om 0t o1

Col
or RED GREEN BLUE Displ
ayed
Code Color
0 0 0 0 Bl
ack
1 0 0 1 Bl
ue
2 0 1 0 Green
3 0 1 1 Cyan
4 1 0 0 Red
5 1 0 1 Magenta
6 1 1 0 Yell
ow
7 1 1 1 White

(ii
)GRAYSCALE:
Withmonitorsthathavenocolorcapabil
it
y,colorf
unct i
onscanbeusedi nan
appli
cationprogram tosettheshadesofgray,orgrayscal
e, f
ordispl
ayedprimiti
ves.
Numericvaluesovertherangefrom 0to1canbeusedt ospecif
ygrayscalel
evel
s,
whichar ethenconv er
tedtoappropri
atebi
narycodesf orstorageintherast
er.
Thisal
lowst heint
ensi
tysett
ingstobeeasilyadaptedt osyst
emswi thdiff
eri
ng
grayscalecapabil
it
ies.Tablel
ist
sthespecif
icati
onsforintensit
ycodesf orafour-
lev
el

13
grayscalesystem.
Inthisexample,anyintensit
yinputv al
uenear0. 33woul dbest oredast hebi naryval
ue
01int heframebuf f
er,andpixelswiththisvaluewouldbedi splayedasdar kgray.
Ifadditi
onalbi
tsperpixel ar
eav ai
lableinthefr
amebuf fer,
thev alueof0. 33woul dbe
mappedt othenearestlevel
.
With3bi t
sperpixel,wecanaccommodat e8gr ayl evel
s; whil
e8bi t
sperpi xelwould
gi
v eus256shadesofgr ay.
Anal t
ernati
veschemef orstor
ingthei nt
ensit
yinf ormationistoconv erteachi nt
ensi
ty
codedi r
ectlytothevolt
agev al
uet hatproducest hi
sgray scalelevelont heout putdev i
ceinuse.

14

You might also like