Write a Program for 2D Translation and Scaling in C

/*
 2D Translation and Scaling
*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int graphdriver=DETECT,graphmode;
int i;
int x2,y2,x1,y1,x,y,sx,sy;

clrscr();

printf("Enter the 2 line end points:");
printf("\n\n x1,y1,x2,y2: ");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

printf("Enter translation co-ordinates ");
printf("x,y");
scanf("%d%d",&x,&y);

printf("\n\n Enter scaling factor: ");
scanf("%d%d",&sx,&sy);

initgraph(&graphdriver,&graphmode,"c:\\turboc3\\bgi");

line(x1,y1,x2,y2);


x1=x1+x;
y1=y1+y;
x2=x2+x;
y2=y2+y;

line(x1,y1,x2,y2);


x1=x1*sx;
y1=y1*sy;
x2=x2*sx;
y2=y2*sy;

line(x1,y1,x2,y2);

getch();
closegraph();
}


Previous
Next Post »