2D Trans Program Akd
2D Trans Program Akd
2D Trans Program Akd
#include "graphics.h"
#include <Windows.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
void main()
{
int ch;
int menu();
void translate();
void scale();
void rotate();
initgraph();
ch = menu();
switch (ch)
{
case 1:
translate();
break;
case 2:
scale();
break;
case 3:
rotate();
break;
}
int menu()
{
int ch;
printf("1. Translation \n");
printf("2. Scaling\n");
printf("3. Rotation\n");
printf("Enter your choice ");
scanf("%d", &ch);
return ch;
}
void translate()
{
int x1, x2, y1, y2, xtran, ytran;
printf("Enter the coordinates of rectangle : \n");
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
printf("Press Enter\n");
getch();
rectangle(x1, y1, x2, y2);
getch();
printf("Enter translation details:\n");
scanf("%d %d", &xtran, &ytran);
printf("Press Enter\n");
x1 = x1 + xtran;
y1 = y1 + ytran;
x2 = x2 + xtran;
y2 = y2 + ytran;
rectangle(x1, y1, x2, y2);
}
void scale()
{
int x1, x2, y1, y2, sx, sy;
printf("Enter the coordinates of rectangle : \n");
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
printf("Press Enter\n");
getch();
rectangle(x1, y1, x2, y2);
getch();
printf("Enter scaling details:\n");
scanf("%d %d", &sx, &sy);
printf("Press Enter\n");
x1 = x1 * sx;
y1 = y1 * sy;
x2 = x2 * sx;
y2 = y2 * sy;
rectangle(x1, y1, x2, y2);
}
void rotate()
{
int x1, x2, y1, y2, r;
float t, nx1, ny1, nx2, ny2;
printf("Enter the coordinates of line : \n");
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
printf("Press Enter\n");
getch();
line(x1, y1, x2, y2);
getch();
printf("\n Enter the angle of rotation");
scanf("%d", &r);
t = r*(3.14 / 180);
nx1 = abs(x1*cos(t) - y1*sin(t));
ny1 = abs(x1*sin(t) + y1*cos(t));
nx2 = abs(x2*cos(t) - y2*sin(t));
ny2 = abs(x2*sin(t) + y2*cos(t));
line(nx1, ny1, nx2, ny2);
getch();
}
Grphics file:
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include <iostream>
#include <math.h>
#include <windows.h>
#include <Windows.h>
using namespace std;
HPEN getPen(int iPEN_STYLE, int iPEN_SIZE, int
iCOLORREF);
BOOL SetPoint(HDC hDC, HPEN hPen, COORD PNT);
BOOL PlotLine(HDC hDC, HPEN hPen, COORD BGN, COORD
END);
BOOL PlotRect(HDC hDC, HPEN hPen, COORD BGN, COORD
END);
BOOL PlotCirc(HDC hDC, HPEN hPen, COORD BGN, COORD
END);
COORD setCordScale(COORD POS, RECT pRECT);
HDC hDC;
HPEN PEN;
HANDLE StdOut;
WORD COLOR;
COORD BGN, POS;
short mov;
short movx;
void initgraph(void)
{
system("cls");
mov = 30;
movx = 0;
HWND hWnd = GetForegroundWindow();
RECT pRECT = { 0 };
COORD POS1 = { 0 };
COORD BGN1 = setCordScale(POS1, pRECT);
GetWindowRect(hWnd, &pRECT);
hDC = GetWindowDC(hWnd);
PEN = getPen(PS_SOLID, 2, RGB(255, 255, 255));
StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
}
void clrscr()
{
setcolor(0);
for (int i = 5; i <= 645; i++)
line(i - movx, 32 - mov, i - movx, 331 -
mov);
}
#endif