/* This program will draw x- y coordinate system and will draw lines in
all quadrants using DDA line drawing algorithm */
Input : x1 , y1 and x2,y2 points ( can input points in all quadrants )
#include<stdio.h>
#include<graphics.h>
#include <stdlib.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,i,xmid,ymid,x1,x2,y1,y2,dx=0,dy=0,steps=0,k,gap=50;
float xin=0.0,yin=0.0,x=0.0f ,y=0.0f;
char str[3];
clrscr();
printf("Enter the co-ordinates");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
steps=abs(dx) ;
else
steps=abs(dy);
xin = dx /(float)steps;
yin =dy /(float)steps ;
initgraph(&gd,&gm,"c:..\\bgi");
xmid= getmaxx()/2;
ymid =getmaxy()/2;
line(5,ymid,getmaxx()-5,ymid);
line(xmid+3,5,xmid+3,getmaxy()-5);
for( i= xmid+gap;i<getmaxx()-5;i=i+gap)
{
outtextxy(i,ymid-3,"|");
itoa(i-xmid,str,10);
outtextxy(i,ymid+3,str);
}
for( i= ymid-gap;i>5;i=i-gap)
{
outtextxy(xmid,i,"-");
itoa(ymid-i,str,10);
outtextxy(xmid+5,i,str);
}
for( i= xmid-gap;i>5;i=i-gap)
{
outtextxy(i,ymid-3,"|");
itoa(-(xmid-i),str,10);
outtextxy(i-6,ymid+3,str);
}
for( i= ymid+gap;i<getmaxy()-5;i=i+gap)
{
outtextxy(xmid,i,"-");
itoa(-(i-ymid),str,10);
outtextxy(xmid+8,i,str);
}
x=x1+xmid;
y=ymid -y1;
putpixel((int)(x+0.5),(int)(y-0.5),7);
for(k=0;k<steps;k++)
{
x=x+xin;
y=y-yin;
putpixel((int)(x+0.5),(int) (y-0.5),7);
}
getch();
closegraph();
}
Input : x1 , y1 and x2,y2 points ( can input points in all quadrants )
#include<stdio.h>
#include<graphics.h>
#include <stdlib.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,i,xmid,ymid,x1,x2,y1,y2,dx=0,dy=0,steps=0,k,gap=50;
float xin=0.0,yin=0.0,x=0.0f ,y=0.0f;
char str[3];
clrscr();
printf("Enter the co-ordinates");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
steps=abs(dx) ;
else
steps=abs(dy);
xin = dx /(float)steps;
yin =dy /(float)steps ;
initgraph(&gd,&gm,"c:..\\bgi");
xmid= getmaxx()/2;
ymid =getmaxy()/2;
line(5,ymid,getmaxx()-5,ymid);
line(xmid+3,5,xmid+3,getmaxy()-5);
for( i= xmid+gap;i<getmaxx()-5;i=i+gap)
{
outtextxy(i,ymid-3,"|");
itoa(i-xmid,str,10);
outtextxy(i,ymid+3,str);
}
for( i= ymid-gap;i>5;i=i-gap)
{
outtextxy(xmid,i,"-");
itoa(ymid-i,str,10);
outtextxy(xmid+5,i,str);
}
for( i= xmid-gap;i>5;i=i-gap)
{
outtextxy(i,ymid-3,"|");
itoa(-(xmid-i),str,10);
outtextxy(i-6,ymid+3,str);
}
for( i= ymid+gap;i<getmaxy()-5;i=i+gap)
{
outtextxy(xmid,i,"-");
itoa(-(i-ymid),str,10);
outtextxy(xmid+8,i,str);
}
x=x1+xmid;
y=ymid -y1;
putpixel((int)(x+0.5),(int)(y-0.5),7);
for(k=0;k<steps;k++)
{
x=x+xin;
y=y-yin;
putpixel((int)(x+0.5),(int) (y-0.5),7);
}
getch();
closegraph();
}
where is itoa() function...
ReplyDeleteDefine..
ReplyDeleteshowing undefine refference..
pls add the header file to solve the problem
ReplyDelete