By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,558 Members | 1,177 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,558 IT Pros & Developers. It's quick & easy.

graphics in c

P: 7
following is a code for scan converting a line using DDA algorithm. But I'm not getting any line segment in the output. The code is:
/*start*/
#include <graphics.h>
#include <stdio.h>
float m;
main()
{
int x1,y1,x2,y2;
float dx,dy;
void slopelessthanone(int,int,int);
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
printf("Enter coordinates of first point:");
scanf("%d%d",&x1,&y1);
printf("Enter coordinates of second point:");
scanf("%d%d",&x2,&y2);
dx=x2-x1;
dy=y2-y1;
m=dy/dx;
printf("%f",m);
if (abs(m)<1) /*I'm considering only one case initially*/
slopelessthanone(x1,x2,y1);
getch();
closegraph();
return;
}
void slopelessthanone(int x1, int y1, int x2)
{
float x,y;
int i=1;
x=x1;
y=y1;
clrscr();
while(x<=x2){
putpixel(x,y,WHITE);
x+=1;
y+=i*m;
i++;
}
}
/*end

Basically in the output when i enter coordinates of the two points, only one dot(i.e. one pixel) gets plotted. There is no line segment. I guess this means that the while loop is executing only once. But i couldn't find the reason.
If anybody could help... thanx!
Aug 12 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
You have the order of the parameters wrong when you call your slopelessthanone() function.

kind regards,

Jos

ps. google for the 'Bresenham' line drawing algorithm; you don't need floats.
Aug 12 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.