Professional Documents
Culture Documents
មេរៀនទី ១២ Graphic
មេរៀនទី ១២ Graphic
RkaPic
GRAPHIC
sBaaNTUeTAn GRAPHIC :
karsMEdgTinnymkelI SCREEN kgTurbo C manrbbBIr KW Text Mode
nwgGraph Mode .
Graph
Mode
minEmnCaxatKMrUrbs;RKb;Pasa
nigma:sIunkMuBUTreT.
eRBaHkarKUsRkahiVcelI Screen, GaRsyedayRbePTkMuBUTrnImYy/ GaRsyedayRbePT
Screen nImYy /////. edIm,IKUsrUb/ pat;BN_rUbPaB////enAelIkMuBUTr/eyIgRtUvbrcrnGKsnIbBaa
Screen BIText ModeeTAGraph Mode.
kuMBUTr/ IBM PC/XT /AT sBVfmaneRcInRbePTxusKadUcxageRkam
- CGA : Color Graphic Adater : crnGKisnIbBaa Screen Color
+ (640 * 200) (manGab;sIus 640 Pixel, manGredaen 200Pixel ) manBIrBN_
+ (320*200) manbYnBN_ .
- MGDA : Monochrome Graphic Display Adapter b Hercule :
I.
243
II.
bNa
eBleRbI Graphic CamYy Turbo C enAelI Disk eyIgRtUv Copy bNa File sMxan;
rbs; Graphic dUcxageRkam
*.TPU
*.BGI
*.CHR
Graphic Interface )
KWCabNa
File
CGA.BGI ;
EGAVGA.BGI ;
HERC.BGI ;
244
Graphic
# include<graphics.h>
# include<conio.h>
main()
{ int gd=DETECT, gm ,errorcode ;
initgraph(&gd,&gm,C:\\TC\\BGI);
errorcode =graphresult () ;
if(errorcode != grOk())
{ printf( Graphics error : %s \n ,grapherrormsg(errorcode));
printf( Press any key to halt : ); getch();
exit(1);
}
(*
getch();
closegraph();
}
manTMrg;
dUcxageRkam
Statement initgraph
Declaration
initgraph( &graphdriver , &graphmode , driverpath ) ;
graphdriver
CGA
MCGA
EGA
EGA64
graphmode
CGAc0,1,2,3,4
CGAHi
MCGA0,,1,,2,,3
MCGAMed
MCGAHi
EGALo
EGAHi
EGA64 Lo
EGA64 Li
245
EGAMono
EGAMono Hi
640 * 350
VGA
VGA Lo
VGA Med
VGA Hi
640 * 200
640 * 350
640 * 480
HercMono
HercMonoHi
720 * 348
ATT400
ATT400 C0,1,2,3
ATT 400 Med
ATT 400 Hi
320 * 200
640 * 400
640 * 400
PC3270
PC 3270 Hi
720 * 350
IBM8514
IBM8514 Lo
IBM8514 Hi
Ex : gd = EGA ; gm = EGAHi ;
initgraph(&Gd,&Gm, C:\\ TC\\BGI ) ;
graphgesult
Function
mantMldUc kgtaragxageRkaenH
eQaH
tMl
grOk()
grNoInitGraph()
-1
grNotDetected()
-2
grFileNotFound()
-3
RbePT kMhus
KankMhus
minTan;dMeNIrkar)an
Gt;manEpk HardWareGraph
Gt;rkeXIjbNa File bBaa
OK,
Graph
246
III.
bNaStatement eRbICamYyGraph :
a, moveto(x,y) ;
KwCa
(0,0)
(getmaxx(),getmaxy())
KUscMnuc
KUscMnucmanlkNCamUldan/ eRBaHcMnucbegIt)anCarUbPaBepSgeTt .
Function
putpixel(int x, int y ,int color) ;
Ca Function KUsEpnrgVg; .
ellipse(int x, int y , int start , int end ,int dx , int dy) ;
sMEdgGtbTelI
SCREEN GRAPH-MODE :
+ moveto (x,y) ;
+ outtext (*st) ;
settextstyle (font, direction, charsize) ;
kMNt;RbePTGkSrCamYy
RbePT Font GkSr
+
- DefaultFont = 0 ;
-TriplexFont = 1 ;
- SmallFont = 2 ;
- SansSerifFont = 3 ;
- GothicFont = 4;
+Direction :
HorizDir = 0 ;
VertDir = 1 ;
+ CharSize :
CharSize
restorecrtmode() ;
Function
setgraphmode() ;
Function
closegraph() ;
Function
VIII. Procedure
-
KUsctuekaNEkg
KUsctuekaNEkgEtmanpat;BN_enApxagkg .
249
250
IX.
kMNt;BN_rUbPaB
{ - - -}
{///}
}
{/ / /
{\ \ \
}
{\ \ \ }
{Light Hatch Fill}
{Heavy cross hatch Fill}
= 9 ; {Interleaving line Fill}
{widely spaced dot Fill}
{Closely Spaced dot Fill}
{
User
}
Edlmanbnat;tUc
EdlmanbnatRkas;;
pat;tamBN_rbs;
begIt
Example :
# include<graphics.h>
# include<conio.h>
# include<stdlib.h>
main()
{int gd=0, gm maxx,maxy ;
char pattern[8]={0x00, 0x70, 0x20, 0x27, 0x25, 0x27,0x04,0x04} ;
initgraph(&gd, &gm, C:\\TC\\BGI);
maxx=getmaxx(); maxy=getmaxy();
setcolor(getmaxcolor());
setfillpattern(pattern, getmaxcolor());
bar(0, 0, maxx, maxy);
getch();
getfillpattern(pattern);
pattern[4] -= 1 ;
pattern[5] -= 3 ;
pattern[6] +=3 ;
pattern[7] -= 4 ;
setfillpattern(pattern,getmaxcolor());
bar(0, 0, max, maxy );
getch ();
closegraph();
251
}
* floodfill(int X, int Y, int Border) ;
KUsBhuekaNehIymanpat;BN_Epkxagkg .
+ PolyPoints : Ca)a:ra:EmRtKanRbePTva pkkUGredaenbNakMBUlrbs;BhuekaN .
+NumPoints: R)ab;cMnYnkUGredaenkg PolyPoints. KWCacMnYnkMBUlrbs;BhuekaN .
kUGredaen mYy man tMlBIr (word : tMlX nig tMlY) . FillPoly
pat;BN_BhuekaNedayeRbI BN_EdlbegIteday SetFillStyle b SetFillPattern .
cMEnkRCugrbs;BhuekaN/ RtUv)anKUsCamYy RbePT bnat; nig BN_ EdlbegIteLIgeday
SetLineStyle .
X. ViewPort :
Procedure
(X1,Y1)
(0,0)
(X2,Y2)
XI.
bNaGnuKmn_epSgeTot
*setlinestyle(int
Ca Function sMrab;kMnt;rageGaybnat;
* bar3d (int x1, int y1 ,int x2 ,int y2, int depth, top );
Ca Function sMrab;KUsctuekaNe)a:gkglMhr .
253
Function
enHbegIt
Dynamic Variable
Ca
edIm,IbegItrUbPaBmanclna kg GraphMode :
- KUsrUb/ Copy rUbenaHcUleTAkg DynamicVariable :
- begIt (Delay) .
- lubrUbenaH/ rMedaHrUbPaBeLIgvijedayeRbI putimage();
- KUsrUbPaBenATItaMgfI .
*
# include<graphics.h>
# include<conio.h>
# include<stdlib.h>
# include<alloc.h>
# include<stdio.h>
void save_screen(void far *buf[4]);
void restore_screen(void far *buf[4]);
int maxx, maxy ;
int main(void)
{ int gd=DETECT, gm ,errorcode ;
void far *ptr[4];
254
initgraph(&gd,&gm,c:\\tc\\bgi);
erorcode = graphresult();
if(errorcode != grOk())
{printf( Graphics error : %s\n,grapherrormsg(errorcode));
printf(Press any key to halt:);
getch();
exit(1);
}
maxx=getmaxx(); maxy=getmaxy();
rectangle(0,0,maxx,maxy);
line(0,0,maxx,maxy);
line(0,maxy,maxx,0);
save_screen(ptr);
getch();
cleardevice();
restore_screen();
getch();
closegraph();
return 0;
}
void save_screen(void far *buf[4])
{ unsigned side;
int ystart = 0 ,yend , yincr , block ;
yincr = (maxy+1)/4;
yend = yincr;
size = imagesize(0,ystart,maxx,yend);
for(block=0; block<=3;block++)
{
if ((buf[block]=farmalloc(size))== NULL)
{closegraph();
printf(Error ! not enough heap space in
save_screen());
exit(1);
}
getimage(0,ystart,maxx,yend,buf[block]);
ystart = yend + 1;
yend += yincr +1;
}
}
void restore_screen(void far *buf[4])
{
int ystart = 0 , yend, yincr , block;
yincr = (maxy+1)/4;
yend = yincr;
for (block=0;block<=3;block++)
{
putimag(0,ystart,buf[block],COPY_PUT);
farfree(buf[block]);
ystart = yend + 1;
255
yend +=yincr + 1;
}
}
=====*=====
256