digital different Analizer(DDA)

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

/*A Program to implement digital different Analizer(DDA)*/

#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
class LINE
{
public:void getdata();
void DrawLine();
void axis();
float x1,y1,x2,y2;
};
void LINE::getdata()
{
clrscr();
cout<<endl<<“Enter the coordinates of startimg point of line”;
cin>>x1>>y1;
cout<<endl<<“Enter rhe coordinates of ending point of line”;
cin>>x2>>y2;
//DrawLine();
clrscr();
}
void LINE::axis()
{
int gm,gd=DETECT;
int midx, midy,x,y;
char s[25];
initgraph(&gd, &gm, “”);
x = getmaxx();
y = getmaxy();
midx=x/2;
midy=y/2;
line(midx,0,midx,y);
outtextxy(x-50,midy-15,”X-axis”);
line(0,midy,x,midy);
settextstyle(0,0,0);
outtextxy(midx+15,10,”Y-axis”);
settextstyle(0,0,0);
for(int i=midy+1;i>-midy;i-=20)
{
line(midx-2,midy-i,midx+2,midy-i);
itoa(i,s,10);
outtextxy(midx-30,midy-i,s);
}
for(i=-midx-1;i<midx;i+=20)
{
itoa(i,s,10);
settextstyle(0,1,0);
outtextxy(i+midx,midy+3,s);
line(i+midx,midy-2,i+midx,midy+2);
}

getch();
closegraph();
}

void LINE::DrawLine()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,” “);
float dx,dy,mx=1,my=1,t1,t2;
cout<<x1<<” “<<y1<<” “<<x2<<” “<<y2;
dx=x1-x2;
dy=y1-y2;
if(dx>dy)
{
mx=dx/dy;
t1=y1;
t2=y2;
}
else
{
my=dy/dx;
t1=x1;
t2=x2;
}
putpixel(x1,y1,15);
do
{
x1=x1+mx;
y1=y1+my;
putpixel(x1,y1,15 );
t1++;
}
while(t1<=t2);

getch();
closegraph();
}

void main()
{
LINE L;
L.getdata();
L.axis();
L.DrawLine();
}

Leave a Reply

Your email address will not be published. Required fields are marked *