You are on page 1of 30
ay Shri Vaishnay Vidyapeeth Vishwavidyalaya, Indore & ¥ Shri Vaishnay Institute of Information Technology rs Department: Campy tea — Sev'ence Code: QT25=50.3 Subject:__74N Session: 201g -20 Semester: ~ Shubhanthe Gnpla TABLE OF CONTENTS 1410 0MBCSEO1344 (S.No. ] Date of Title Remarks Performing Study of vauus fonelons 17 Guuphis Header Fi'k. Waite a potognars to draw & B howe —_usihe Fone-bont . Wute a progzars to display & oa | 18 Jo#9' | 02 | 22 opis os | 22 Joza a Moving can. wte a prograrr to implegent By | ieee eae ge ee 1! wate a program to Inplemant os | slosla| “Craorbun'e the Oren ing Agere. 26, To Implement genemb'ztal breser her's of | real) irnle — dnawtes. aiiaraie wWrule a am lo implement mid) oF |26/og)is Pairk cle dawriga rhea pee 2 Wate @ Prregiam to hrarblate 0g.) o> ee Line and bniangle. wile 2 wyum +0 pertarre dha, on a twagk. wuwite a 0 to perham ap |) blest Plans on a trvangle. h Wwe 4 pregnam te Inplement Ke Jection 2 aa |ashshs Gren baretibn « | 04 | 02 Jes}ig Shri Vaishnay Vidyapeeth Vishwavidyalaya, Indore Shri Vaishnay Institute of Information Technology Department: Gmaton Seiexe hati le: CTs. Subject: _ ary TABLE OF CONTENTS S.No. Date of Session; 9¢19 ~ 20 Semester; 47 Title | Remarks Sutherlard Hodgman polygon Meping algon'the| | Performing A so] 14 Liat? a program to impleyent Fhod. —— Fit affanithm. ‘) 13| 50/09) Wute a progam 10 implement Bovrdary / fu Algerithra . 44 worle a Praga to implenent Chen ade chipping algerithmn . 45| syufg| We 0 Prpram 4p duw a GEZTER 9 Lune. 46 | orfofy| To Study G-SPlne Cue. i imcdie basis Softe P27) oy/nfiy | 1 shel ee hase Sofhare 4B oy]ng Wile a freyran to (meplerrenb. Experiment No. 01 : To study functions of Graphics header file. aphics (graphics.h) - C Programming. aphics programming in C used to drawing various geometrical shapes(rectangle, circle eclipse etc), Function Name Declar Description void eirle(int x, int y, Intradius); Circle function is used to draw a circle with center (xy) and third parameter specifies the raclus of the circle ‘Closegraph void closegraph) ‘losegraph function closes the graphics mode, deallocates all memory allocated by graphics system and restores the screen to the mode it wasin before you called initgraph. Ellipse void elipsetint nt intstange, int endange, int radius, Intra); Ellipse Is used to draw an ellipse (xy) are coordinates of center ofthe ellipse, stangle isthe starting angle, end angle is the ending angle, and fifth and sixth parameters specifies the X and Y radius of the ellipse. To draw a complete ellipse strangles and end angle should be 0 and 360 respectively. Fillpoly void drawpaly( int rum, int *polypoints}; Fillpoly function draws and fills polygon. Itrequire same arguments drawpoly Getpixel int getpixel{int x int yj ietpixel function eturns the color of pixel present at locationtx,y)- void ine(intxd, int vi, int x2, int y2}; line function is used to draw a line from a point(xt,y1) to point(x2,y2) Le. (x,y4) and (02,y2) are end points of the line. The code given below draws aline. ‘unsigned int Imagesizeint left, int top, int right, int bottom); Imagesize function returns the number of bytes required to store a bitimage. This function is used when, we are using getimage. Linerel function draws a ine ‘] from the current position(CP) to a point that | Bis a relative distance (x,y) | from the CP, then advances | | the CP by (x v). You can use agetx and gety to find the | current position | void putimage(int left, | putpixel function plots a | int top, void *ptr, int | pixel at location (x, v) of | op}; “specified color | void getimage(int left, | putimage puts the bit image | int top, int right, int previously saved with bottom, void *bitmap); | getimage back onto the screen, with the upper left ‘corner of the image placed at (left, top). ptr points to the area in memory where the source image is stored. The op argument specifies @ operator that controls how the color for each destination pixel on screen is computed, based on pixel already on screen and the corresponding source pixel in memory. Getpixel Getbkcolor int getpixel(intx, inty); | getpixel function returns the color of pixel present at location(x, int getbkcolor(); ‘getbkcolor function returns the current background color e.g. color = getbkcolor(); // color is an int variable if current background color is GREEN then color will be fe 2 int getx(); ‘The function getx returns the X coordinate of the current position. int gety() gety function returns the y coordinate of current position. void setcolorfint color); | In Turbo Graphies each color is assigned a number. Total 16 colors are available. Strictly speaking number of available colors depends on Inttop, int right, bottom); void rectangle(int left, current graphics mode and | driver.For Example » BLACK |S assigned 0, RED is assigned 4 ete, setcolor function is used to. change the current drawing color.e.g. setcolor(RED) or setcolor(4) changes the Current drawing color to RED. Remember that default drawing color is WHITE ‘rectangle function is used to int, draw a rectangle. Coordinates of lefttop and right bottom corner are required to draw the rectangle. left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left ‘corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner. The code given below draws rectangle, int texthelght(char ‘textheight function returns *string); the height of a string in By ns pivels. Textwidth int textwidth(char | Textwidth function returns string); the width of a string in pixels Cleardevice void cleardevice(); cleardevice function clears the screen in graphics mode and sets the current position to (0,0), Clearingthe screen consists of filing the screen with current background color. Getdrivername setdrivername function returns a pointer to the | current graphics driver Initgraph void initgraph( it *pathtodriver); *graphdriver, int *graphmode, ch int initgraph initializes the raphies system by loading a graphics driver from disk (or validating a registered driver), and putting the system into graahies mode, Experiment No.02 : To Draw House Using Graphics.h Code pathdriver, (&gd,2gm, pathdriver); {150,190,250,300}; Experiment No.7 Aim ; Write a program to implement mid point circle drawing algorithm. Source Code : Wincludecgraphics.h> #include Hincludecstdio.h> void main() { int gd=DETECT,gm; int i.x=0,y,xc,ye; float 4; alrscr(); initgraph(8&gd,8gm,"c:\te\\"); printf("Enter Radius\n"); scanf{"3%d", 8); printf("Enter Center of circle\n"): scanf("%d",Buxc); sscanf("%d",&yc); d=1.25-r; yr, do { if(d<0.0) { x41; d=d42"91; ) else { xex41; veel; d=d42"x-2*y+10; )  putpixel(xctx,ycty,5); Putpixel(xc-y,ye-x,5); Putpixel(xcty,ye-x,5); Putpixel(xc-y, yo+x,5); putpixel(xcty.¥e 4,5); pputpixel(xcive v5); putpixellxctye v5); putpixel(xcrx.ye +5); ) whilexsy)i goteh() ) Experiment No, 08 : Write program to translate line and triangle. XAy1,x2,y2,tx,ty, x3,y3,x4, ya; "Enter the Coordinates of line\n"); I"%A%S%d%A" x1, Ry, Bx2,&y2); "Enter the Translation Factors\n"); "Hed %d" Bit, ty); "Original Line\n"); e(xi,yi.x2,y2); aK +oGy3=y1+ty; =x2+txy4=y2+ty; A("%d%d%d%d" x3,y3,x4,y4); "Line After Translation\n"); orlint i=0;i clude float x,y,x1,y1,x2,y2,sx,sy,dx,dy, dx1,dy1,dx2,dy2; inti,gd=DETECT, gm; initgraph(&gd,8gm,"c:\\turboc3\\bgi"); printf("Enter the value of x and scanf("26f96f", &x,&y); printf("Enter the value of x1 and y1: "); scanf("%f%F", &x1,&y1); printf("Enter the value of x2 and y2 scanf("%F%F", 22, y2); printf("enter the value of scaling factor:"); scanf("%f%E",&sx,&sy); line(xy,x1,y1); line(x1,y1,x2,y2); line(x2,y2,x,y); dx=x*sx; dy=y*sy; dy2=y2* sy; line(dx,dy,dx1,dy4); line(dxt,dy4,dx2,dy2); line(dx2,dy2,dx,dy); getch(); closegraph(); Experiment No. 10 Aim: Write a program to perform rotation ofan Triangle Source Code: #include sinclude include include void main( ) { float x,y,x1,y1,x2,y2,5x,sy,dx,dy,dx1,dy,dx ,dy2, t=" : Pee pencnn: dx, dy1,d2,dy2,t=0.0174,q; initgraph(&ed,&gm,"c:\\turboc3\\bgi"); printf("Enter the value of x and y :"); scanf("%f%F", &x,&y); printf("Enter the value of x1 and ya: "); scanf("9f%f", &x1,&y1); printf("Enter the value of x2 and y2 :"); scanf{"%6f9%f",8x2,&y2); printf("Enter the value of rotation angle : *); scanf("9%6f", &q); line(x,y,x1,y1); lime(x,y1,x2,y2);, line(x2,y2,x,y); tt(q); dx=x*cos(t)-y*sin(t); dy=x*sin(t)+y*cos(t); 1*cos(t)-y1*sin(t); *sin(t)+y1*cos(t); *cos(t)-y2*sin(t); dy2=x2*sin(t)+y2*cos(t); line(dx,dy, dx1,dy1); line(dx1,dy1,dx2,dy2); lime(dx2,dy2,dx, dy); getch(); closegraph(); Experimen, te |; Write a program to j implement Reflecti i ion Ty Dn x-axis transformation about: int gd-DETECT, int xmidymid x1.y1,x2,y2,x3,y3.x11,x22,33,y11,y2,y33 option; elrser(); initgraph(&ed,&gm,”.\\bgi"); primti("Enter first co-ords of the tiangle\n") scantt"%d Yed",&x1,&y1); . printf("Enter second co-ords of the triangle\n"); seanl("%d Yd" &Xx2,8y2): printf("Enter third co-ords of the triangle\n"); seanf("%d %d",&x3,&y3);, xmid=geimaxx()/2; ymid=getmaxy()/2; Jine(0.ymid,getmaxx(),ymid): Jine(xmid,0.xmid,getmaxy()); line(x1-+xmid,ymid-y1.x2+xmid.ymid-y2); Tine(x24xmid,ymid-y2,x3+xmid,ymic line(x3-+xmid,ymii print{("Enter1:To reflect the Triangle about x-axii printi("Enter2:To reflect the Triangle about y-axis. printf("enter your ch scanf("%d",&option); switch(option) ‘ case 1: Vime(x 1 #xmidyymid-y1 fine(x22+xmid.ymid- Xinty.int old_color.int fill color); 1.x2,y1,y2; gd,&gm); &gm,' Cl TurboC3//BGI") ‘top-left point of rectangle: asl yl) i hia of rectangle: "); iy xd | color) © elix.y.fill_ color): fll(xtL.y.old_color.fill color); fill(xy+ L.old_color.fill_ color): sd fill(x-1.y,old_color.fill colon: d_ fill(x.y-l.old color.fill_ color), EXPERIMENT NO. -13 e a program to implement Boundary Fill algorithm. y_fill(int x,int y,int boundary_color,int Sll_color); Ax2.yliy2; sph(K&yd.&em): ph(&ed,&gm,"C://TurboC3//BGI"); jer top-left point of rectangle: "); %d" &X1,&y1): iter bottom-right point of rectang! d%d". &x2.&V2): cel(x,y)5 I-boundary color&& current!=fill_color) _ putpixel(x.y.fill_color); delay(10 ary _{ill(x+1.y.boundary_color.fill_ color); sundary_fill(x.y+1,boundary_color,{ill_color): oundary_fill(x-1,y,boundary_color.fill_ color); soundary_fill(x,y-1,boundary color, fill_color); oBJECTIVE: WRITE CERIN. J al COHEN SUTHERLAND jy, Lippi PLEMENT proGRAM: GORITHM. ginelude 4inelude finelude void main() { int g4=DETECT, gm; fost imax.ymax,xminyminxty 99 float start[4],end[4},code[4);, SYVX2.V2.m: clrscr(); initgraph(&gd,&em,"): ymin=100; : printf("\nEnter x1 and y1: "); scanf("%f %f",&x1,&y1); printf("\nEnter x2 and y2:"); seanf("%f %F",&x2,&y2): Jine(x1,y1,x2,y2); for(i=0;i xmax) start{1]=1; iffy >ymax) start{2]=1: iffy] xmax) end[]=1: iffy2 >ymax) end{2}=1; ifly2

You might also like