0% found this document useful (0 votes)
42 views4 pages

Experiment No.02: Pratiksha D. Laldas SE Computer A Roll NO.53

This document describes experiments implementing two line drawing algorithms: Digital Differential Analyser (DDA) and Bresenham's algorithm. It includes the C code for both algorithms and displays the output of drawing lines using each one. The conclusion states that both algorithms were successfully studied and implemented for line drawing.

Uploaded by

piyush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

Experiment No.02: Pratiksha D. Laldas SE Computer A Roll NO.53

This document describes experiments implementing two line drawing algorithms: Digital Differential Analyser (DDA) and Bresenham's algorithm. It includes the C code for both algorithms and displays the output of drawing lines using each one. The conclusion states that both algorithms were successfully studied and implemented for line drawing.

Uploaded by

piyush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Pratiksha D.

Laldas
SE Computer A
Roll NO.53

EXPERIMENT NO.02

AIM:IMPLEMENTATION OF LINE DRAWING ALGORITHM DIGITAL DIFFERENTIAL ANALYSER


& BRESENHAM'S ALGORITHM

 DIGITAL DIFFERENTIAL ANALYSER

#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#define Round(x) ((int)(x+0.5))

void main()
{
int i;
float x1 =100,x2=200,y1=20,y2=170,l,dx,dy,x,y;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode," ");
dx=x2-x1;
dy=y2-y1;
if(dx>dy)
{
l=dx;
}
else
{
l=dy;
}
dx=(float)(dx)/l;
dy=(float)(dy)/l;
x=x1;
y=y1;
for(i=0;i<100;i++)
{
putpixel(i+200+Round(x),200-Round(y),1);
putpixel(-i+200+Round(x),200-Round(y),2);
putpixel(200+Round(x),i+200-Round(y),3);
putpixel(200+Round(x),-i+200-Round(y),4);
}
for(i=0;i<l;i++)
{
putpixel(Round(x)+200,-Round(y)+200,4);
x=x+dx;
y=y+dy;
}
delay(150000);

closegraph();
}

OUTPUT:

 BRESENHAM'S ALGORITHM

#include<iostream.h>
#include<graphics.h>

void drawline(int x0, int y0, int x1, int y1)


{
int dx, dy, p, x, y;

dx=x1-x0;
dy=y1-y0;

x=x0;
y=y0;

p=2*dy-dx;

while(x<x1)
{
if(p>=0)
{
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
}
else
{
putpixel(x,y,7);
p=p+2*dy;
}
x=x+1;
}
}

int main()
{
int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");

cout<<"Enter co-ordinates of first point: ";


cin>>x0>>y0;

cout<<"Enter co-ordinates of second point: ";


cin>>x1>>y1;
drawline(x0, y0, x1, y1);

return 0;
}
OUTPUT:

CONCLUSION:

Hence, we successfully studied and implemented line drawing algorithm Digital


Differential Analyser(DDA) and Bresenham’s Algorithm

You might also like