-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoolTextRotation.cpp
More file actions
166 lines (148 loc) · 4.4 KB
/
CoolTextRotation.cpp
File metadata and controls
166 lines (148 loc) · 4.4 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
##########
by cyber-ikaros with love
##########
*/
#include <iostream>
#include<windows.h>
#include <thread>
#include <math.h>
using namespace std;
void ShowConsoleCursor(bool showFlag)
{
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = showFlag;
SetConsoleCursorInfo(out, &cursorInfo);
}
void SetCoolConsoleFont()
{
CONSOLE_FONT_INFOEX cf = { 0 };
cf.cbSize = sizeof cf;
cf.dwFontSize.X = 12;
cf.dwFontSize.Y = 16;
wcscpy_s(cf.FaceName, L"Terminal");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), 0, &cf);
}
void SetCursorPosition(const int x, const int y)
{
COORD position;
position.X = x;
position.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);
}
void PrintAt(string in_s, int x, int y)
{
SetCursorPosition(x, y);
cout << in_s;
}
void PrintColoredAt(string in_s, int x, int y, int color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
PrintAt(in_s, x, y);
}
void PrintHorizontalRotated(string in_s, int x, int y, int alpha, int color)
{
string a = in_s;
int clampedAlpha = alpha % a.length();
rotate(a.begin(), a.begin() + clampedAlpha, a.end());
PrintColoredAt(a, x, y, color);
}
void PrintColoredFrame(string in_s, int x, int y, int color, int alpha)
{
for (int j = x; j < x+in_s.length()+2; j++)
{
PrintColoredAt("-", j, y-1, color);
}
PrintColoredAt("|", x, y, color);
PrintHorizontalRotated(in_s, x+1, y, color, alpha);
PrintColoredAt("|", x+in_s.length()+1, y, color);
for (int j = x; j < x+in_s.length()+2; j++)
{
PrintColoredAt("-", j, y+1, color);
}
}
void PrintAnotherColoredFrame(string in_s, int x, int y, int color)
{
for (int j = x; j < x + in_s.length() + 2; j++)
{
PrintColoredAt("-", j, y - 1, color);
}
PrintColoredAt("|", x, y, color);
PrintColoredAt(in_s, x + 1, y, color);
PrintColoredAt("|", x + in_s.length() + 1, y, color);
for (int j = x; j < x + in_s.length() + 2; j++)
{
PrintColoredAt("-", j, y + 1, color);
}
}
void PrintRotated(string in_s, int x, int y, int color, int origin, int rotation)
{
rotation = rotation % 8;
if (origin == 0)
{
int length = in_s.length();
switch (rotation)
{
case 0:
for (int i = 0; i < length; i++)
{ PrintColoredAt(string{ in_s[i] }, x+i, y, color); }
break;
case 1:
for (int i = 0; i < length; i++)
{ PrintColoredAt(string{ in_s[i] }, x + i, y + i, color); }
break;
case 2:
for (int i = 0; i < length; i++)
{ PrintColoredAt(string{ in_s[i] }, x, y + i, color); }
break;
case 3:
for (int i = 0; i < length; i++)
{ PrintColoredAt(string{ in_s[i] }, x-i, y+i, color); }
break;
case 4:
for (int i = 0; i < length; i++)
{ PrintColoredAt(string{ in_s[i] }, x - i, y, color); }
break;
case 5:
for (int i = 0; i < length; i++)
{ PrintColoredAt(string{ in_s[i] }, x - i, y - i, color); }
break;
case 6:
for (int i = 0; i < length; i++)
{ PrintColoredAt(string{ in_s[i] }, x, y - i, color); }
break;
case 7:
for (int i = 0; i < length; i++)
{ PrintColoredAt(string{ in_s[i] }, x + i, y - i, color); }
break;
}
}
}
void ClearSector(int fromX, int fromY, int size)
{
for (int i = fromY; i < fromY + size + 1; i++)
{
string a = "";
for (int j = 0; j < size; j++)
a.append(" ");
PrintAt(a, fromX, i);
}
}
int main()
{
//set console settings
SetCoolConsoleFont();
ShowConsoleCursor(false);
//colored text!!!
for (int i = 5; i < 14; i++)
{
this_thread::sleep_for(std::chrono::milliseconds(100));
PrintAnotherColoredFrame(" Hello! I'm TorgaW! ", 10, 6, i);
ClearSector(10, 9, 17);
PrintRotated(" Hello! ", 20, 15, i+1, 0, i-5);
PrintColoredFrame(" Hello! ", 15, 25, i, i);
if (i == 13) i = 5;
}
}