0

I have the following code for DDA Line Algorithm in C :-

//DDA Line Algorithm

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

#define Round(a) ((int)(a+0.5))

void linDDA(int xa,int ya,int xb,int yb);

int main()
{
  int gdriver=DETECT,gmode;
  initgraph(&gdriver,&gmode,"E:\\TC\\bgi");
  linDDA(10,20,200,100);
  clrscr();
  getch();
  return 0;
}

void linDDA(int xa,int ya,int xb,int yb)
{
 int dx,dy,steps,k;
 float xincr,yincr,x=xa,y=ya;

 dx=xb-xa;
 dy=yb-ya;

 if(abs(dx)>abs(dy))
 steps=abs(dx);
 else
 steps=abs(dy);

 xincr=dx/(float)steps;
 yincr=dy/(float)steps;

 putpixel(Round(x),Round(y),20);           //plotting the first point

 for(k=0;k<steps;k++)
 {
  x+=xincr;
  y+=yincr;
  putpixel(Round(x),Round(y),20);
 }
}

The code compiles fine but in the output I get a white screen on a black background. There is no line printed in the output. Please help!!

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by gaurav_13191
0

You are clearing the screen, immediately AFTER you call the function!

Try clearing the screen BEFORE you call the function! ROFL! ;)

0

Well that proves that I seriously need some changes. This has happened with me a lot of times earlier too. Thanks anyway..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.