Hello
I am try to learn Brasenham Line Drawing Algorithm. I wrote this program in Turbo C

``````# include <stdio.h>
# include <conio.h>
# include <graphics.h>

void main()
{
int dx,dy,x,y,p,x1,y1,x2,y2;
int gd,gm,errorcode;
clrscr();
printf("\n\n\tEnter the co-ordinates of first point : ");
scanf("%d %d",&x1,&y1);
printf("\n\n\tEnter the co-ordinates of second point : ");
scanf("%d %d",&x2,&y2);

dx = (x2 - x1);
dy = (y2 - y1);

p = 2 * (dy) - (dx);

x = x1;
y = y1;

gd=DETECT,gm,errorcode;
initgraph(&gd,&gm,"e:\\tc\\bgi");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("%s",grapherrormsg(errorcode));
getch();return;
}
putpixel(x,y,WHITE);

while(x <= x2)
{
if(p < 0)
{
x=x+1;
y=y;
p = p + 2 * (dy);
}
else
{
x=x+1;
y=y+1;
p = p + 2 * (dy - dx);
}
putpixel(x,y,WHITE);
}
getch();
closegraph();

}
``````

if I enter coordinates - 180,250,500,600 the output a line going diagnoly downwards, but if I enter 500,600,180,250 i am getting BLANK SCREEN.
Please explain if I'm wrong

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Ancient Dragon

gd=DETECT,gm,errorcode;

Line 23: What is that trying to do?

if I enter 500,600,180,250 i am getting BLANK SCREEN.

Print out the value of the calculations, x and y are probably off the screen.

This topic has been dead for over six months. 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.