The TurboC code:
#include<stdio.h>
#include<graphics.h>
#include<math.h>
int transx(int x,int amag)
{
if(amag>1)
x=x*amag;
x=320+x;
return(x);
}
int transy(int y,int amag)
{
if(amag>1)
y=y*amag;
y=240-y;
return(y);
}
void magnify(int x,int y,int color,int d,int basepix)
{
int i,j;
d=(d*2)-1;
for(i=d;i>=-d;--i)
{
for(j=d;j>=-d;--j)
{
putpixel(x+i,y+j,color);
}
}
putpixel(x,y,basepix);
}
void initgmode()
{
int GraphDriver,GraphMode,ErrorCode;
GraphDriver = DETECT;
initgraph(&GraphDriver,&GraphMode,"E:\\TC\\BGI");
if((ErrorCode=graphresult())!=grOk)
{
printf("\nERROR : %s\n",grapherrormsg(ErrorCode));
exit(1);
}
}
void axes(int color,int basepix,int d,int show)
{
int i,j,k;
int c=getcolor();
if(show==1)
{
for(i=0;i<=480;i++)
{
putpixel(320,i,color);
if(d>1)
for(k=1;k<=(320/d);k++)
{
putpixel(320-(k*d),i,basepix);
putpixel(320+(k*d),i,basepix);
}
}
for(i=0;i<=640;i++)
{
putpixel(i,240,color);
if(d>1)
for(k=1;k<=(240/d);k++)
{
putpixel(i,240+(k*d),basepix);
putpixel(i,240-(k*d),basepix);
}
}
}
setcolor(15);
outtextxy(330,2,"Y");
outtextxy(2,250,"X'");
outtextxy(330,250,"O:(0,0)");
outtextxy(628,250,"X");
outtextxy(330,468,"Y'");
setcolor(c);
putpixel(320,240,basepix);
}
void main()
{
int x0,y0,magstat;
int degree=1;
int axis_color=4;
int axis_mag=1;
int show_grid=1;
int color=14;
int basepix_col=3;
char choice='y';
do
{
clrscr();
printf("\n\nEnter magnification preference: \n");
printf("------------------------------------\n");
printf("i) Press '0' to magnify the pixels only.\n");
printf("ii) Press '1' to magnify the entire grid.\n");
printf("Enter your choice:");
do
{
scanf("%d",&magstat);
if((magstat!=1)&&(magstat!=0))
printf("\n\nERROR in input! Please enter either 0 or 1: ");
}while((magstat!=1)&&(magstat!=0));
if(magstat==1)
{
printf("\nEnter the grid magnificaton degree (>=2): ");
do
{
scanf("%d",&axis_mag);
if(axis_mag<=1)
printf("\nERROR in input! Please enter a value >0");
}while(axis_mag<=1);
}
do
{
printf("\nEnter the pixel magnification degree (>=1): ");
scanf("%d1",°ree);
if(degree<1)
printf("\n\nERROR! Degree sould be > 0. Insert again!");
}while(degree<1);
printf("\n\nEnter the X-cordinate : ");
scanf("%d",&x0);
printf("Enter the Y-coordinate : ");
scanf("%d",&y0);
x0=transx(x0,axis_mag);
y0=transy(y0,axis_mag);
clrscr();
initgmode();
axes(axis_color,basepix_col,axis_mag,show_grid);
magnify(x0,y0,color,degree,basepix_col);
getch();
closegraph();
do
{
printf("Do You Want to Continue? (y/n) :");
fflush(stdin);
scanf("%c",&choice);
if((choice!='y')&&(choice!='Y')&&(choice!='n')&&(choice!='N'))
printf("ERROR! please enter either 'y' or 'n'\n\n");
}while((choice!='y')&&(choice!='Y')&&(choice!='n')&&(choice!='N'));
}while((choice=='y')||(choice=='Y'));
}
No comments:
Post a Comment