Practical No.01: -WAP to draw various Graphics object using Graphics function.
#Include<stdio.h>
#include<conio.h>
Void main()
Int gd=DETECT,gm;
Initgraph(&gd,&gm,”C:\\Turboc3\\BGI”);
Putpixel(100,100,WHITE);
Line(150,150,250,250);
Circle(300,300,50);
Ellipse(400,400,0,360,50,25);
Rectangle(450,150,600,300);
Line(200,200,250,100);
Line(250,100,300,200);
Line(300,200,200,200);
Int poly[]={320,150,370,200,350,250,290,250,270,200,320,150);
drawpoly(6,poly);
getch();
closegraph();
OUTPUT: -
Practical No.02: -WAP to draw line using DDA algorithm.
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
Void main()
Float x,y,x1,y1,x2,y2,dx,dy,step;
int i, gd =DETECT ,gm;
initgraph(&gd, &gm,”C:\\Turdoc3\\BGI”);
printf(“Enter the value of x1 and y1:”);
scanf(“%f,%f”,&x1, &y1);
printf(“Enter the value of x2 and y2:”);
scanf(“%f,%f”,&x2, &y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
step=dx;
else
step=dy;
dx=dx/step;
dy=dy/step;
x=x1;
y=y1;
i=1;
while(i<=step)
Putpixel(x,y,5);
x=x+ dx;
y=y+ dy;
i=i+1;
delay(100);
Closegraph();
OUTPUT: -
Practical No.03: -WAP to draw a line using Bresenham’s Algorithm.
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void BresenhamLine(int x1, int y1, int x2, int y2);
void main()
int gd=DETECT ,gm;
int x1, y1, x2, y2;
initgraph(&gd, &gm,”C:\\TC\\BGI”);
printf(“Enter the coordinates of the first point(x1,y1):”);
scanf(“%d%d”,&x1,&y1);
printf(“Enter the coordinates of the second point(x2,y2):”);
scanf(“%d%d”,&x2,&y2);
BresenhamLine(x1, y1, x2, y2);
getch();
closegraph();
Void BresenhamLine(int x1, int y1, int x2, int y2);
int dx, dy, p, x, y, xEnd;
dx=x2-x1;
dy=y2-y1;
x=x1;
y=y1;
if(x1>x2)
x=x2;
y=y2;
x2=x1;
y2=y1;
P=2*dy-dx;
For(x=x1;x<=x2,x++)
putpixel(x, y, WHITE);
if(p>0)
y++;
p=p+2*(dy-dx);
else
p=p+2*dy;
OUTPUT: -
Practical No.04: - WAP to draw circle using Bresenham’s algorithem.
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
Void main()
int gd=DETECT, gm, tmp, i=1, rds;
float st_x, st_y, x1, x2, y1, y2, ep;
initgraph(&gd, &gm,”C:\\Turboc3\\BGI”);
printf(“Enter Radius:”);
scanf(“%d”,&rds);
while(rds>pow(2,i))
i++;
ep=1/pow(2,i);
x1=rds;
y1=0;
st_x=rds;
st_y=0;
do
x2=x1+(y1*ep);
y2=y1-(x2*ep);
putpixel(x2+200,y2+200,10);
x1=x2;
y1=y2;
while((y1-st_y)<ep||(st_x-x1)>ep);
getch();
}
OUTPUT:-