Draw axis on screen in c++

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//program To Draw axis on the screen

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>//for itoa()
class axis
{
private :
int x,y,x1,y1,x2,y2;
public :
void initgraph1(void);
void drawaxis(void);
};
void axis :: initgraph1(void)
{
int gd = DETECT, gm;
initgraph(&gd,&gm,”c:\\tc\\bgi”);
}
void axis :: drawaxis(void)
{
/*
putpixel(0,0,WHITE);//upper left corner
putpixel(0,getmaxy(),WHITE); //lower left corner
putpixel(0,getmaxy()/2,WHITE);//center left
putpixel(getmaxx()/2,0,WHITE);//center upper
putpixel(getmaxx(),0,WHITE);//upper right corner
putpixel(getmaxx(),getmaxy(),WHITE);//lower right corner
putpixel(getmaxx(),getmaxy()/2,WHITE);//center right
putpixel(getmaxx()/2,getmaxy(),WHITE);//lower center
*/
line(((getmaxx()/2)-(getmaxy()/2)),getmaxy()/2,(getmaxx()-((getmaxx()/2)-(getmaxy()/2))),getmaxy()/2);//horizontal line
line(getmaxx()/2,0,getmaxx()/2,getmaxy());//verticle line
putpixel(getmaxx()/2,getmaxy()/2,RED); //center point
outtextxy(570,235,”X-axis”); //x-axis
outtextxy(330,0,”Y-axis”); //y-axis
//circle(getmaxx()/2,getmaxy()/2,getmaxy()/2);

//for generating scale
x1 = getmaxx()/2; //center co-ordinates (x1,y1)
y1 = getmaxy()/2;
char ch[10] = ” “;
int scale = 0;
outtextxy(x1+5,y1+5,”0”); //for putting 0 in center
for(int i=1;i<=10;i++)
{
scale = scale + 10;
itoa(scale,ch,10);
putpixel(x1+(2*scale),y1,RED); //putting pt. on +ve X-axis.
putpixel(x1,y1-(2*scale),RED); //putting pt. on +ve Y-axis.
outtextxy(x1+(2*scale),y1+5,ch); //scale on +ve X-axis.
outtextxy(x1+5,y1-(2*scale),ch); //scale on +ve Y-axis.
}
scale = 0;
for(i=1;i<=10;i++)
{
scale = scale – 10;
itoa(scale,ch,10);
putpixel(x1+(2*scale),y1,RED); //putting pt. on -ve X-axis.
putpixel(x1,y1-(2*scale),RED); //putting pt. on -ve Y-axis.
outtextxy(x1+(2.5*scale),y1-10,ch); //scale on -ve X-axis.
outtextxy(x1+5,y1-(2*scale),ch); //scale on -ve Y-axis.
}
}
/*
void main()
{
clrscr();
axis a;
a.initgraph1();
a.drawaxis();
getch();
}
*/

Leave a Reply

Your email address will not be published. Required fields are marked *