You are on page 1of 13

SUNNY 81005218115

1./* Program to draw a line and circle */

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

int gd=DETECT,gm;

int a,b,c,d;

initgraph (&gd,&gm,"c:\\tc\\bgi");

printf("Enter the coordinate for a line");

scanf("%d%d%d%d",&a,&b,&c,&d);

line(a,b,c,d);

printf("Enter the coordinate for a circle");

scanf("%d%d%d",&a,&b,&c);

circle(a,b,c);

getch();

closegraph();

OUTPUT:
Enter the coordinate for a line60

30

100

30

1
SUNNY 81005218115

Enter the coordinate for a circle150

150

80

2./* Program to draw a triangle */

2
SUNNY 81005218115

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

int gd=DETECT,gm;

int a,b,c,d;

initgraph (&gd,&gm,"c:\\tc\\bgi");

printf("Enter the coordinate for a line");

scanf("%d%d%d%d",&a,&b,&c,&d);

line(a,b,c,d);

printf("Enter the coordinate for a line");

scanf("%d%d%d%d",&a,&b,&c,&d);

line(a,b,c,d);

printf("Enter the coordinate for a line");

scanf("%d%d%d%d",&a,&b,&c,&d);

line(a,b,c,d);

getch();

closegraph();

OUTPUT:
Enter the coordinate for a line60

3
SUNNY 81005218115

30

100

30

Enter the coordinate for a line60

30

90

20

Enter the coordinate for a line90

20

100

30

4
SUNNY 81005218115

3. /* Program to draw ellipse and rectangle */

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

int graphic_driver=0,graphic_man,x1,y1,x2,y2,Vr,Hr;

initgraph(&graphic_driver,&graphic_man,"");

printf("Enter the coordinate for X and Y to draw an ellipse");

scanf("%d%d",&x1,&y1);

printf("Enter the vertical and Horizontal distance from origin");

scanf("%d%d",&Vr,&Hr);

ellipse(x1,y1,0,360,Vr,Hr);

printf("Enter the first coordinate to draw a rectangle ");

scanf("%d%d",&x1,&y1);

printf("Enter the second coordinate");

scanf("%d%d",&x2,&y2);

rectangle(x1,y1,x2,y2);

getch();

closegraph();

5
SUNNY 81005218115

OUTPUT:
Enter the coordinate for X and Y to draw an ellipse200

150

Enter the vertical and horizontal distance from origin70

40

Enter the first coordinate to draw a rectangle300

200

350

250

6
SUNNY 81005218115

4./* Program to check error */

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

int error_check,graph_driver=DETECT,graph_mode;

clrscr();

initgraph(&graph_driver,&graph_mode,"");

error_check=graphresult();

if(error_check!=0)

printf("Error=%s",grapherrormsg(error_check));

getch();

OUTPUT:
Error=Device driver file not found(EGAVGA.BGI)

7
SUNNY 81005218115

5.PROGRAM TO FILL A RECTANGLE WITH DIFFERENT


FILLSTYLES.

#include<stdlib.h>
#include<dos.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
for(int i=EMPTY_FILL;i<USER_FILL;i++)
{
setfillstyle(i,2);
setcolor(4);
delay(700);
rectangle(100,100,200,200);
floodfill(150,170,4);
}
getch();
closegraph();
}

*****-OUTPUT-*****

8
SUNNY 81005218115

6. PROGRAM TO RANDOMLY GENERATE CIRCLE ONTO THE


SCREEN.

#include<stdlib.h>
#include<dos.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
while(!kbhit())
{
setcolor(random(getmaxcolor()));
circle(random(500),random(400),random(90));
delay(200);
}
getch();
closegraph();
}
*****-OUTPUT-*****

9
SUNNY 81005218115

7. program to draw a line using DDA algorithm.


#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

void main()

float x1,y1,x2,y2,dx,dy,steps,i;

float xinc,yinc;

int gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\tc\\bgi");

printf("enter the values");

scanf("%f %f %f %f",&x1,&y1,&x2,&y2);

dx=x2-x1;

dy=y2-y1;

x=x1;

y=y1;

if(abs(dx)>abs(dy))

steps=dx;

else

steps=dy;

10
SUNNY 81005218115

xinc=dx/steps;

yinc=dy/setps;

for(i=0;i<steps;i++)

putpixel(x,y,4);

x=x+xinc;

y=y+yinc;

getch();

***************OUTPUT****************

Enter the values :- 110,130,140,220

11
SUNNY 81005218115

8. Program to draw the line using bresenham’s algorithm.


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,p;
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter the values");
scanf("%f %f %f %f",&x1,&y1,&x2,&y2);
dx=x2-x1;
dy=y2-y1;
p=2*dy-dx;
i=0;
fflush(stdin);
while(!kbhit())
{
x=x1;
y=y1;
putpixel(x,y,i);

while(x<x2)
{
if(p<0)
p=p+2*dy;
else
{
p=p+2*dy-2*dx;
y++;
}
x++;
putpixel(x,y,i);

}
delay(500);
i++;

}
getch();
closegraph();
}

12
SUNNY 81005218115

********************OUTPUT*******************

13

You might also like