-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTranslation.cpp
50 lines (37 loc) · 1.1 KB
/
Translation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <graphics.h>
void RectAngle(int x, int y, int Height, int Width, int color)
{
// Set the color based on the input
setcolor(color);
// Draw the four sides of the rectangle
line(x, y, x + Width, y); // Top side
line(x, y, x, y + Height); // Left side
line(x + Width, y, x + Width, y + Height); // Right side
line(x, y + Height, x + Width, y + Height); // Bottom side
}
void Translate(int x, int y, int Height, int Width, int color)
{
int Newx = 50, Newy = 50; // Assigning values directly
// Calculate the new position of the rectangle after translation
int a = x + Newx;
int b = y + Newy;
// Draw the translated rectangle in the specified color
RectAngle(a, b, Height, Width, color);
}
int main()
{
int gd = DETECT, gm;
// Initialize the graphics system
initgraph(&gd, &gm, "");
// Define colors
int blue = BLUE;
int red = RED;
// Draw the original rectangle in blue
RectAngle(100, 100, 50, 100, blue);
// Translate the rectangle and draw it in red
Translate(100, 100, 50, 100, red);
getch();
closegraph();
return 0;
}