L12 graphic

Page 1

emeronTI12 ³

RkaPic GRAPHIC

sBaØaNTUeTAén GRAPHIC : karsMEdgTinñn½ymkelI SCREEN kñúgTurbo C manrbbBIr KW ³Text Mode nwgGraph Mode . Graph Mode minEmnCaxñatKMrUrbs;RKb;Pasa nigma:sIunkMuBUüT½reT. eRBaHkarKUsRkahiVcelI Screen, GaRs½yedayRbePTkMuBUüT½rnImYy²/ GaRs½yedayRbePT Screen nImYy² /////. edIm,IKUsrUb/ pat;BN_rUbPaB////enAelIkMuBUüT½r/eyIgRtUvbþÚrcrnþGKÁsnIbBa¢a Screen BIText ModeeTAGraph Mode. kuMBUüT½r/ IBM – PC/XT /AT sBVéf¶maneRcInRbePTxusKñadUcxageRkam ³ - CGA : Color Graphic Adater : crnþGKÁisnIbBa¢a Screen Color + (640 * 200) (manGab;sIus 640 Pixel, manGredaen 200Pixel ) manBIrBN_ + (320*200) manbYnBN_ . - MGDA : Monochrome Graphic Display Adapter b¤ Hercule : I.

243


-

crnþGKÁisnIbBa¢a Screens-exμA (monochrome)/ + 720 * 348 (manGab;sIus 720Pixel,manGredaen 348Pixel ) EGA : Enhanced Graphic Adapter : crnþGKÁisnIbBa¢a Screen Color + 640 * 350 nigGaceRCIserIs)an 16BN_ . VGA : Video Graphic Array : 640 * 480

Super VGA : 1024 * 768 :

II.

bNþa

GaceRCIserIs)andl; 256 BN_.

FILE rbs; Graphic :

eBleRbI Graphic CamYy Turbo C enAelI Disk eyIgRtUv Copy bNþa File sMxan;² rbs; Graphic dUcxageRkam ³ *.TPU *.BGI *.CHR

nwgenAedImkmμviFI eyIgRtUv Proto Type edIm,IeRbI GRAPH.TPU dUcxageRkam ³ # include<graphics.h>

bNþa File *.BGI (BGI : Borland pÞúkbNþaXøabBa¢a Screen epSgKñadUcCa ³ +

Graphic Interface )

KWCabNþa

File

CGA.BGI ; EGAVGA.BGI ; HERC.BGI ;

bNþa File *.CHR CabNþa File pÞúkbNþaXøabBa¢asMrab;KUsRbePTGkSrkñúg dUcCabNþa File xageRkamenH ³ GOTH.CHR (GkSr Gothic) +

LITT.CHR (Small Font)

GkSr Sons Serif) TRIP.CHR (GkSrFMCag3dg /Triplex) edIm,Igayyl;rebobeRbIRkahVic/ eyIgBinitü ]TahrN_KUsbnñat;BImMuEkgxagelIEpñk xageqVgcuHmk mMuEkg xageRkam EpñkxagsþaM ³ SANS.CHR (

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); }

naM Cursor Graph eTAcMnucmMuEkgxagelI/EpñkxageqVg *) lineto(getmaxx(),getmaxy() ) ; (* KUsbnÞat; *) moveto(0,0) ;

(*

getch(); closegraph(); }

manTMrg;

dUcxageRkam ³

Statement initgraph Declaration initgraph( &graphdriver , &graphmode , driverpath ) ;

KWCa Statement begáIt (Greate Graphics) RkahVic kñúgenaH ³ + graphdriver pÞúktMélkMNt;RbePT Screen : 0 DETECT 3 EGA 6 IBM8514 9 VGA 1 CGA 4 EGA 64 7 HercMono 10 PC3270 2 MCGA 5 RGAMono 8 ATT 400

pÞúktMélkMNt; Mode RkahVic . +driverpath R)ab;eGay Turbo C sÁal; Directory EdlpÞúkbNþa File bBa¢aRkahiVc . taragxageRkamenHbgðajeQaHrbs;bNþatMélrbs; GraphDriver,graphMode : +graphmode

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

320 * 200 CGA 640 * 200 CGA 320 * 200 320 * 200 640 * 480 640 * 200 Ù CGA 640 * 350 640 * 200 Ù CGA 640 * 350


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

640 * 480 ,, 256COLOR 1024 * 768 ,, 256COLOR

man Variable 2 KW : &gd, &gm .munenHebIsinCa graphdriver RtUv)ankMnt; edaytMél DETECT enaH initgraph nwgkMnt;yk graphdriver nig graphmode Edll¥bMput ¬emIlkñúgtaragxagelI¦. lT§plnwgpþl;eGay &gd, &gm smmUlnwg graphdiver, graphmode . kñúgkrNI Screen man Mode eRcInRbePTxusKña/ eyIgGaceRCIserIs gaphdrver, smrmü edaymineRbIrebobkMnt;tMéleGay Gd = GraphMode DETECT;EteyIgkMNt;tMélsmrmüeGay gd nig gm muneBlehA initgraph . Statement initgraph

Ex : gd = EGA ; gm = EGAHi ; initgraph(&Gd,&Gm, “ C:\\ TC\\BGI” ) ; graphgesult Function

KWCa Function rbs; Tur bo C ,vaeGayeyIgdwgBIsßanPaBrbs; Graphic .

mantMéldUc kñúgtaragxageRkaenH ³ eQμaH tMél grOk()

0

grNoInitGraph()

-1

grNotDetected()

-2

grFileNotFound()

-3

RbePT kMhus

KμankMhus minTan;dMeNIrkar)an Gt;manEpñk HardWareGraph Gt;rkeXIjbNþa File bBa¢a OK,

Graph

246


III.

bNþaStatement eRbICamYyGraph : a, moveto(x,y) ;

KwCa

bBa¢ÚnTItaMg CP(Current-Position) eTAcMnucEdlmankUGredaen X,Y. Cursor kñúg Screen graph kMNt;edaykUGredaen vaGt;mancMnucPøWelatPøwbePøt²dUckñúg ScreenText eT . Statement

(0,0)

(getmaxx(),getmaxy())

GnuKmn_ getx(), gety() pþl;nUvkUGredaenén Cursor-Graph. b,lineto (x,y);

KWCa Statement KUsbnÞat;Rtg;BITItaMg Cursor-Graph bc©úb,nñeTAcMnucEdlmankUGredaen (X,Y) bnÞab;BI KUsrYc Cursor-Graph sßitenATItaMgfμIEdlmankUGredaen (X,Y) Function getmaxx(),getmaxy(),eRbIedIm,IKNnacMnYncMnucGtibrmatamGk½S Gab;sIusnigG½kS Gredaen . mann½y fa/ CakUGredaencMnucénmMuEkgxageRkamEpñkxagsþaM. Ex cMeBaH EGA Screen, enaH getmaxx = 639, getmaxy = 349 . ÷edIm,IrkSa Screen-Graph kñúgkarBinitüemIllT§pleyIgeRbI Statement getch() . ÷edIm,IbBa¢b; Graph Mode eyIgeRbI Statement closesgraph() ; IV. Function

KUscMnuc ³

KUscMnucmanlkçN³CamUldæan/ eRBaHcMnucbegáIt)anCarUbPaBepSg²eTüt .

Function putpixel(int x, int y ,int color) ;

KUscMnucPøWRtg;TItaMgEdlmankUGredaen (X,Y) manBN_Ca Color . 247


getpixel( int x, int y ) ;

Ca Function bgðajR)ab;BN_bc©úb,nñRtg;cMnuc (X,Y) . V. Function KUsbnÞat;Rtg;

³

line(int x1, int y1, int x2, int y2 ) ;

Ca Function KUsbnÞat;Rtg;BIcMnucEdlmankUGredaen (X1,Y1) eTAcMnuc (X2,Y2). vaminGaRs½yeTAnwg TItaMgén CP ( Current-Position) . eRkayBIKUsrYc CPnwgsßitenARtg;cMnuc (X2,Y2) , eBlenaH LineTo(X,Y) nwg KUsbnÞat;BITItaMg CP eTAcMnuc (X,Y) . linerel( int dx, int dy ) ;

Ca Function KUsGgát;Rtg;BITItaMg CP eTAcMnucfμIEdlmankUGredaen (X + dx, Y + dy). eRkayBIKUsrYc / CP sßitenAcMnucfñI (X+dx,Y+dy). VI. Function KUsrgVg;

³

circle(int x, int y , int R ) ;

Ca Function KUsrgVg;Edlmanp©itRtg;cMnun (X,Y), mankaM R . pieslice( int x, int y , int start, int end ,int R ) ;

Ca Function KUsEpÞénrgVg; . ellipse(int x, int y , int start , int end ,int dx , int dy) ;

Ca Function KUs Ellipse . VII.

sMEdgGtþbTelI

SCREEN GRAPH-MODE :

kñúg graphmode, Statement printf() nwg cprintf() minRsbnwg ScreenGraph eTeRBaHvaeRbIxñatkUGredaen CacMnYn character . eyIgman Function BIrsMrab;sMEdgGtþbTelI ScreenGraph : -

outtext (char *st) ;

sMEdgGtþn½yrbs; St Rtg;cMnuc CP (Current Position) enAelI ScreenGraph . 248


-

outtextxy ( int x, int y , char *st ) ;

sMEdgGtþn½yrbs; St Rtg;cMnuc (X,Y) enAelI ScreenGraph . dUecñH outtextxy smmUlnwg Command BIxageRkam ³ -

+ 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 :

TTYltMélBI 1 dl; 10/ CaemKuNedIm,IBRgIktYGkSr .

-

CharSize restorecrtmode() ;

-

Function setgraphmode() ;

-

Function closegraph() ;

enHeRbIsMrab;Rtlb;eTA TextMode beNþaHGsnñ . enHeRbIsMrab;Rtlb;eTA GrapgMode vij .

Function

enHeRbIsMrab;biT GrapgMode ehIyRtlb;eTA TextMode vij .

VIII. Procedure -

KUsctuekaNEkg ³

rectangle(int x1, int y1, int x2, int y2 ) ;

KUsctuekaNEkgEdlman (X1,Y1) CakUGredaenéncMnucmMuEkgxagelIEpñkxageqVg/ nig (X2,Y2) Ca kUGredaenéncMnucmMuEkgxageRkamEpñkxagsþaM . -

bar(int x1, int y1, int x2, int y2 ) ;

KUsctuekaNEkgEtmanpat;BN_enAépÞxagkñúg . 249


xusBI rectangle() Rtg; rectangle() RKan;EtKUsRCugrbs;ctuekaNEkgb:ueNÑaH vaGt;pat;BN_xag kñúgeT . bar() -

drawpoly( int NumPoints ,int PolyPoints) ;

Ca Function KUsBhuekaN/ RtIekaN ……. -polypoints : Ca)a:ra:EmRtGt;RbePT/ vapÞúkkUGredaenénbNþakMBUlrbs;BhuekaN . -numpoints : bgðajcMnYnkUGredaenkñúg PolyPoints ( CacMnYnkMBUlrbs;BhuekaN ) . kUGredaenmYyman tMélBIrCaRbePT int. tMélmYyCaGab;sIus X, nigtMélmYyeTütCaGredaen Y . cMNaM ³ edIm,IKUsBhuekaNEdlman N RCug/ eyIgRtUvpþl; N+1 kUGredaeneTA DrawPoly . Example : # include<graphics.h> # include<stdlib.h> #include<conio.h> main() { int gd=DETECT, gm, errorcode; int poly={20,240,620,20,590,460,320,240,20,240} ; 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); } drawpoly(5,poly); getch(); closegraph(); return 0; }

250


IX.

kMNt;BN_rUbPaB ³

* setfillstyle ( int Pattern, int Color) ;

kñúgenaH Pattern CacMnYnKt;BI 0 dl; 12 EdlmaneQμaH nigtMélEdl)ankMNt;niymy½mehIy ³ EmptyFill =0; { BN_exñA } SolidFill =1; { BN_Rkem:ARbepH } LineFill =2; LtSlashFill = 3 ; SlashFill =4; BkSlashFill = 5 ; LtBkSlashFill = 6 ; HatchFill =7; XHatchFill = 8 ; InterLeaveFill WideDotFill = 10 ; CloseDotFill = 11 ; UserFill = 12 ;

{ - - -} {///} } {/ / / {\ \ \ } {\ \ \ } {Light Hatch Fill} {Heavy cross hatch Fill} = 9 ; {Interleaving line Fill} {widely spaced dot Fill} {Closely Spaced dot Fill} { User }

EdlmanbnÞat;tUc EdlmanbnÞatRkas;;

pat;tamBN_rbs;

begáIt

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) ;

eyIgeRbI function enHedIm,Ipat;BN_eGayctuekaN/ RtIekaN/ BhuekaN>>>>>>>>>>/cMnuc (X,Y) RtUvsßit enAkñúgépÞu én ctuekaN. BN_Edlpat;enaHRtUv)anbegáIteLIgeday setfillstyle b¤ setfillpattern . Border (mantMélBI 0 dl; 15) CaBN_rbs;RCug . ebIcMnuc (X,Y) sßitenAkñúgépÞctuekaN/ enaHEpñkxagkñúgctuekaN RtUv)anpat;BN_ EtebIcMNuc (X,Y) enAeRkA ctuekaNvijenaHKWEpñkxageRkActuekaNRtUv)anpat;BN_ . * fillpoly( NumPoints , PolyPoints) ;

KUsBhuekaNehIymanpat;BN_Epñkxagkñúg . + PolyPoints : Ca)a:ra:EmRtKñanRbePTva pÞúkkUGredaenbNþakMBUlrbs;BhuekaN . +NumPoints: R)ab;cMnYnkUGredaenkñúg PolyPoints. ¬KWCacMnYnkMBUlrbs;BhuekaN¦ . kUGredaen mYy man tMélBIr (word : tMélX nig tMélY) . FillPoly pat;BN_BhuekaNedayeRbI BN_EdlbegáIteday SetFillStyle b¤ SetFillPattern . cMEnkRCugrbs;BhuekaN/ RtUv)anKUsCamYy RbePT bnÞat; nig BN_ EdlbegáIteLIgeday SetLineStyle . X. ViewPort :

CatMbn;ctuekaNEkgmYyenaelI Screen EdleyIgGacGnuvtþbNþa rbs; Graphic enAkñúg enaH hak;bIdUcCa Screen tUcmYy . Viewport

Procedure

setviewport (int X1,int Y1,int X2,int Y2, Clip) ;

Ca Function kMNt; ViewPort mYyenAelI Screen CamYy (X1,Y1,X2,Y2) CakUGredaenrbs; ViewPort . eRkay BIehA esetviewport / kUGredaen (0,0) énbNþa Statement KUsnwgkøayCamMuEkg xagelI EpñkxageqVgrbs; ViewPort KW (X1,Y1) . )a:ra:EmRt Clip GacmantMél True = clipon : GnuBaØatieGayemIleXIjbNþabnñat;EdlKUsecjeRkA ViewPort , cMENk clipoff nwgminGacemIleXIj bnñat;EdlKUsecjeRkA ViewPort . 252


(X1,Y1) (0,0)

(X2,Y2)

mMukUGredaenfñIeRkayBIehA setviewport(X1,Y1,X2,Y2, Clip) eyIgGacpøas;bþÚr ViewPort enARKb;kénøgkñúgkmμviFIedIm,I)ankUGredaenKUs nig tMbn;KUssmRsb. ]TahrN_KUsRkahVicrbs;smIkarEdlmanmMu kUGredaenenAkNþal SCREEN : setviewport (getmaxx() / 2, getmaxy() / 2, getmaxx(), getmaxy(), 1 );

XI.

bNþaGnuKmn_epSgeTot ³

*setlinestyle(int

LineStyle,int Pattern,int Thickness);

Ca Function sMrab;kMnt;rageGaybnÞat; * bar3d (int x1, int y1 ,int x2 ,int y2, int depth, top );

Ca Function sMrab;KUsctuekaNe)a:gkñúglMhr .

kat;rUb/ biTrUb nig begáItrUbPaBEdlmanclna ³ rkSaTukrUbPaB ³ XII.

edIm,IrkSaTukrUbPaBNamYy/ eyIgRtUveRbI Block Memory mYyEdlmanragCa ctuekaNEkgBT_§CMuvij rUbPaBenaH . eRkaymkeyIgrkSaépÞRklactuekaNEkgenaH.edIm,IKNnaTMhM Block Memory rag ctuekaN EkgpÞúkrUbPaBenaH/ eyIgeRbI Function manRsab; KW ³ + imagesize(int X1, int Y1,int X2 , int Y2 ) ;

253


edIm,IerübcM Memory rkSaTukrUbPaB/eyIgeRbI minkMnt; RbePT .

Function

enHbegáIt

Dynamic Variable

+ getimage(int X1,int Y1,int X2, int Y2 , *PBitMap) ;

Ca

edIm,I Copy bNþacMnucénrUbPaBenAelI Screen EdlsßitkñúgctuekaN (X1,Y1,X2,Y2) cUleTA kñúg Memory EdlRtUv PBitMap CaGñk Index, edayeRbI Procedure GetMem xagelI . Procedure

+ putimage(int X, int Y , *PBitMap , int CopyMode) ;

rMedaHrUbPaBEdleyIg)an Copy eday GetImage, mkelI Screen Rtg;cMnuc (X,Y). kñúgenaH CopyMode CaRbePT Copy rUbPaBmkelI Screen : Copy = 0 XORPut = 1 ORPut = 2 ANDPut = 3 NOTPut = 4

edIm,IbegáItrUbPaBmanclna kñúg GraphMode : - KUsrUb/ Copy rUbenaHcUleTAkñúg DynamicVariable : - begáIt (Delay) . - lubrUbenaH/ rMedaHrUbPaBeLIgvijedayeRbI putimage(); - KUsrUbPaBenATItaMgfñI . *

# 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


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.