// This is Digital differential analyzer(DDA) line drawing algorithm using C
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
void jayudda(float,float,float,float);
void main()
{
int gdriver = DETECT, gmode;
float x1,y1,x2,y2;
initgraph(&gdriver, &gmode, "..\\bgi");
printf("enter starting points(x1,y1):"),scanf("%f%f",&x1,&y1);
printf("enter ending points(x2,y2):"),scanf("%f%f",&x2,&y2);
jayudda(x1,y1,x2,y2);
getch();
}
void jayudda(float x1,float y1,float x2,float y2)
{
int i;
float sign;
if(abs(x2-x1)>abs(y2-y1))
sign=abs(x2-x1);
else
sign=abs(y2-y1);
for(i=0;i<=sign;i++)
{
putpixel(x1,y1,7);
x1+=(x2-x1)/sign;
y1+=(y2-y1)/sign;
}
}
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
void jayudda(float,float,float,float);
void main()
{
int gdriver = DETECT, gmode;
float x1,y1,x2,y2;
initgraph(&gdriver, &gmode, "..\\bgi");
printf("enter starting points(x1,y1):"),scanf("%f%f",&x1,&y1);
printf("enter ending points(x2,y2):"),scanf("%f%f",&x2,&y2);
jayudda(x1,y1,x2,y2);
getch();
}
void jayudda(float x1,float y1,float x2,float y2)
{
int i;
float sign;
if(abs(x2-x1)>abs(y2-y1))
sign=abs(x2-x1);
else
sign=abs(y2-y1);
for(i=0;i<=sign;i++)
{
putpixel(x1,y1,7);
x1+=(x2-x1)/sign;
y1+=(y2-y1)/sign;
}
}
No comments:
Post a Comment