Animation.Console

 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
#include <Windows.h>
void Circle (HWND hW, int xCenter, int yCenter, int radius, COLORREF borderColor, COLORREF fillColor) {
HDC hDC = GetDC(hW);
HPEN hPen = CreatePen(PS_SOLID, 1, borderColor);
HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);
HBRUSH hBrush = CreateSolidBrush(fillColor);
HBRUSH hOldBrush = (HBRUSH) SelectObject(hDC, hBrush);
Ellipse(hDC, xCenter - radius, yCenter - radius, xCenter + radius, yCenter + radius);
SelectObject(hDC, hOldPen);
DeleteObject (hPen);
SelectObject(hDC, hOldBrush);
DeleteObject (hBrush);
ReleaseDC (hW, hDC);
}
void Line (HWND hW, int x0, int y0, int x1, int y1, COLORREF color) {
HDC hDC = GetDC(hW);
HPEN hPen = CreatePen(PS_SOLID, 2, color);
HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);
SelectObject(hDC, hPen);
POINT p = {0,0};
GetCurrentPositionEx (hDC, &p);
MoveToEx(hDC, x0, y0, &p);
LineTo (hDC, x1, y1);
SelectObject(hDC, hOldPen);
DeleteObject (hPen);
ReleaseDC (hW, hDC);
}
void Picture (HWND hW, int dx, int dy, int mode) {
COLORREF border = RGB(255,255,0), fill = RGB (127,127,0), line = RGB (0,255,0), black = RGB (0,0,0);
if (!mode) border = fill = line = black;
int x0 = 50, y0 = 50, r = 10;
Circle (hW, x0 + dx, y0 + dy, r, border, fill);
Line (hW, x0 + dx, y0 + dy + r, x0 + dx, y0 + dy + r + 30, line);
Line (hW, x0 + dx, y0 + dy + r + 30, x0 + dx - 10, y0 + dy + r + 70, line);
Line (hW, x0 + dx, y0 + dy + r + 30, x0 + dx + 10, y0 + dy + r + 70, line);
Line (hW, x0 + dx - 5, y0 + dy + r + 7, x0 + dx + 5, y0 + dy + r + 2, line);
Line (hW, x0 + dx - 5, y0 + dy + r + 7, x0 + dx - 10, y0 + dy + r + 25, line);
Line (hW, x0 + dx + 5, y0 + dy + r + 2, x0 + dx + 10, y0 + dy + r + 20, line);
}
int main() {
HWND hW = GetConsoleWindow();
int step = -1;
Sleep (1000);
for ( ; ;++step) {
Picture (hW, 5*step,0,1);
Sleep (200);
Picture (hW, 5*step,0,0);
if (step > 100) step = -10;
}
system ("pause");
return 0;
}