Wednesday, November 17, 2010

Program to show translation and scaling in 2D































//Program to show translation and scaling in 2D

#include
#include
#include
#include

void translate();
void scale();
void main()
{
int ch;
int gd=DETECT,gm;
initgraph(&gd,&gm,"e:\\tc\\bgi");

setcolor(WHITE);
outtextxy (50,50,"Object.");
rectangle(100,100,300,200);

printf("---MENU---");
printf("\n 1)Translate\n 2)Scale");
printf("\nEnter your choice: ");
scanf("%d",&ch);
cleardevice();

switch(ch)
{
case 1: translate();
break;
case 2: scale();
break;
default: printf("you have enterd wrong choice");
break;
}
getch();
closegraph();
}

void translate()
{
int tx,ty;
setcolor(WHITE);
outtextxy(240,10,"TRANSLATION");
outtextxy(238,20,"------------");
printf("\nEnter tx: ");
scanf("%d",&tx);
printf("\nEnter ty: ");
scanf("%d",&ty);
cleardevice();
setcolor(BROWN);
rectangle(100,100,300,200);
setcolor(WHITE);
outtextxy(10,250,"After Translation");
rectangle(100+tx,100+ty,300+tx,200+ty);
}

void scale()
{
int b,r;
float sx,sy;
setcolor(WHITE);
outtextxy(240,10,"SCALING");
outtextxy(238,20,"--------");
printf("\nEnter sx: ");
scanf("%f",&sx);
printf("\nEnter sy: ");
scanf("%f",&sy);
cleardevice();
r=200*sx+100;
b=100*sy+100;
outtextxy(20,250,"After");
outtextxy(10,260,"Scaling");
setcolor(BROWN);
rectangle(100,100,300,200);
setcolor(WHITE);
rectangle(100,100,r,b);
}

No comments:

Post a Comment