Graphics Lab Course Material

of 15
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
  1)/* Program to initialize the graph and draw a line * / #include<graphics.h> #include<conio.h> void main() { int gd =DETECT: /*Detect the graph driver dynamically*/ int gm; /*for graph mode*/ initgraph (&gd,&gm,’’’); /* graph driver, graph mode and path has to be passed as parameters. The empty path is specified means the path will be taken dynamically after searching in the computer. Otherwise we need to spcify the path where bgi directory is stored in the computer */ line(10,10,200,200); /* this function draws a line from starting co-ordinates(10,10) to the target co-ordinates (200,200). These co-ordintes are specified in terms of pixels */ getch(); closegraph(); /* close the graph mode */  } 2) /* program to draw a rectangle , lines as its diagonals and a circle */ #include<graphics.h> #include<conio.h> void main() { int gd=DETECT; int gm; initgraph(&gd,&gm,””); rectangle(10,10,200,200); /* draws a rectangle */ line(10,10,200,200); /* draw a line on the main diagonal*/ line(10,200,200, 10); /* draws a line on off diagonal */ circle(105,105,95); /* draws a circle taking (105,105) as center co-ordinates and 95 as radius all the dimensions are in pixels */ getch(); closegraph(); /*closes the graph mode */  }   3) /* program to draw a circle and ellipses */ #include<graphics.h> #include<conio.h> void main() { int gd=DETECT; int gm; Initgraph (&gd,&gm,””); Circle (getmaxx ()/2,getmaxy ()/2,100); /*draws a circle taking midpoint of the screen as center co-ordinates and 100 as radius */ setcolor(2); /*sets the drawing color as green */ ellipse(getmaxx()/2,0,360,80,50); /* draws an ellipse taking center of the screen as its center , 0 as starting angle and 360 as ending angle and 80 pixel as Y radius */ setcolor(4); /*sets the drawing color as red */ ellipse(getmaxx()/2, getmaxy()/2,90,270,50, 80); /*draws half the ellipse starting from 90 angle and ending at 27o angle with 50 pixels as X-radius and 80 pixels as Y-radius in red color */ getch(); closegraph(); /* closes the graph mode */  } 4) /* program to demonstrate put pixel */ # include<graphics.h> # include<conio.h> # include <stdlib.h> # include<dos.h> void main() { int gm, gd=DETECT,I; initgraph(&gd, &gm,’’’’); while(!kbhit())/* until pressing any key this loop continues */ { putpixel(rand()%getmaxx(), rand() % getmaxy(), rand()%16);  /*x and y co-ordinates and the color are taken randomly*/ delay(2); /* just to draw the pixels slowly*/  } getch (); closegraph(); /* closes the graph mode */  } 5) /* Program to demonstrate rectangles using putpixel and filling them with different fill effects */ # Include <graphics.h> # Include <conio.h> # include <stdlib.h> # include <dos.h> void main() { int gm,gd= DETECT; int x1,x2,y1,y2,c,I; initgraph(&gd,&gm,’’’’); while(!kbhit()) /* until pressing any key this loop continues */ { /* To draw rectangle co-ordinatinates are taken randomly */ x1=rand()%getmaxx(); x2=rand()%getmaxx();  y1=rand()%getmaxy();  y2=rand()%getmaxy(); if (x1>x2) { c=x1; /* exchange of x1 and x2 when x1 is >x2 */ x1=x2; x2=c;  } if(y1>y2) { c=y1; /* exchange of y1 and y2 when y1 is > y2 */  y1=y2;   y2=c;  } c=rand()%16; /* for rectangle using putpixel */ for(I=x1 ;i<=x2;++i) { putpixel(I,y1,c); delay (1);  } for(i=y1;I<=y2;++i) { putpixel(x2,I,c); delay(1);  } for(i=x2;i>=x1; i) { putpixel(i,y2,c); delay(1);  } for(i=y2;I>=y1; i) { putpixel(x1,i,c); delay(1);  } setfillsytyle(rand()%12, rand()%8); /* setting the random fill styles and colors * floodfill(x1+1,y1+1,c); delay(200); /* to draw the pixels slowly */  } getch(); closegraph(); /* closes the graph mode */  } 6) /* Program to demonstrate lines with different colors and co-ordinates */ #include<graphics.h> #include<conio.h> #include<stdlib.h> #include<dos.h>
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks