/* .......Works on Win XP */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x,y,d,x1,x2,y1,y2,dx,dy,dt,ds;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI"); /*Sometimes it may be "c:\\tc\\bgi" , It depends machine to mac..*/
printf("Enter start and end coordinates x1 y1 & x2 y2 ");
scanf("%d%d%d%d",&x1,&y1,x2,y2);
dx=x2-x1;
dy=y2-y1;
dt=2*(dy-dx);
ds=2*dy;
d=2*dy-dx;
putpixel(x1,y1,YELLOW);
while(x1<x2)
{
x1++;
if(d<0)
d=d+ds;
else
{
y1++;
d=d+dt;
}
putpixel(x1,y1,YELLOW);
}
getch();
closegraph();
}
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x,y,d,x1,x2,y1,y2,dx,dy,dt,ds;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI"); /*Sometimes it may be "c:\\tc\\bgi" , It depends machine to mac..*/
printf("Enter start and end coordinates x1 y1 & x2 y2 ");
scanf("%d%d%d%d",&x1,&y1,x2,y2);
dx=x2-x1;
dy=y2-y1;
dt=2*(dy-dx);
ds=2*dy;
d=2*dy-dx;
putpixel(x1,y1,YELLOW);
while(x1<x2)
{
x1++;
if(d<0)
d=d+ds;
else
{
y1++;
d=d+dt;
}
putpixel(x1,y1,YELLOW);
}
getch();
closegraph();
}
No comments:
Post a Comment