/
*CSEMATTER.BLOGSPOT.IN
PROGRAM NAME-PROGRAM TO DRAW A LINE IN A SHIFTED ORIGIN*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{int gd=DETECT,gm;
float x1,x2,y1,y2;
float m,c,x,y,i;
printf("enter the first coordinatse");
scanf("%f %f",&x1,&y1);
x1=x1+320;
y1=240-y1;
printf("enter the second coordinatse");
scanf("%f %f",&x2,&y2);
x2=x2+320;
y2=240-y2;
m=(y2-y1)/(x2-x1);
c=y1-(m*x1);
initgraph(&gd,&gm,"C:\tc\bgi");
line(320,0,320,480);
line(0,240,640,240);
if(x2!=x1)
{ x=x1;
y=y1;
while(x<=x2)
{ y=(m*x)+c;
putpixel(x,y,15);
x++;}
}
else
printf("ERROR!!!!!!");
getch();
closegraph();
}
*CSEMATTER.BLOGSPOT.IN
PROGRAM NAME-PROGRAM TO DRAW A LINE IN A SHIFTED ORIGIN*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{int gd=DETECT,gm;
float x1,x2,y1,y2;
float m,c,x,y,i;
printf("enter the first coordinatse");
scanf("%f %f",&x1,&y1);
x1=x1+320;
y1=240-y1;
printf("enter the second coordinatse");
scanf("%f %f",&x2,&y2);
x2=x2+320;
y2=240-y2;
m=(y2-y1)/(x2-x1);
c=y1-(m*x1);
initgraph(&gd,&gm,"C:\tc\bgi");
line(320,0,320,480);
line(0,240,640,240);
if(x2!=x1)
{ x=x1;
y=y1;
while(x<=x2)
{ y=(m*x)+c;
putpixel(x,y,15);
x++;}
}
else
printf("ERROR!!!!!!");
getch();
closegraph();
}
No comments:
Post a Comment