#include <iostream>
#include <Windows.h>
using namespace std;
HWND hWnd = GetConsoleWindow();
HDC hDC = GetDC(hWnd);
void DrawOctagon(HDC hDC, COLORREF color, int cx, int cy, int w, int h)
{
HPEN hPen = CreatePen(PS_SOLID, 2, color);
HBRUSH hBrush = GetStockBrush(NULL_BRUSH);
SelectObject(hDC, hPen);
SelectObject(hDC, hBrush);
POINT pt[8];
// Вычисляем 8 точек восьмиугольника
pt[0].x = cx + w / 2; pt[0].y = cy;
pt[1].x = cx + w - w / 4; pt[1].y = cy;
pt[2].x = cx + w; pt[2].y = cy + h / 2;
pt[3].x = cx + w - w / 4; pt[3].y = cy + h;
pt[4].x = cx + w / 2; pt[4].y = cy + h;
pt[5].x = cx + w / 4; pt[5].y = cy + h;
pt[6].x = cx; pt[6].y = cy + h / 2;
pt[7].x = cx + w / 4; pt[7].y = cy;
Polygon(hDC, pt, 8);
DeleteObject(hPen);
}
int main()
{
int squareX = 100;
int squareY = 100;
int squareSize = 300;
int w = 80;
int h = 60;
COLORREF bg = GetPixel(hDC, 0, 0);
// Движение вправо (ширина уменьшается)
for (int x = squareX; x <= squareX + squareSize - w; x += 5)
{
DrawOctagon(hDC, bg, x - 5, squareY, w, h);
w = max(20, w - 1);
DrawOctagon(hDC, RGB(255, 0, 0), x, squareY, w, h);
Sleep(30);
}
// Движение вниз
for (int y = squareY; y <= squareY + squareSize - h; y += 5)
{
DrawOctagon(hDC, bg, squareX + squareSize - w, y - 5, w, h);
DrawOctagon(hDC, RGB(255, 0, 0), squareX + squareSize - w, y, w, h);
Sleep(30);
}
// Движение влево (ширина увеличивается)
for (int x = squareX + squareSize - w; x >= squareX; x -= 5)
{
DrawOctagon(hDC, bg, x + 5, squareY + squareSize - h, w, h);
w = min(80, w + 1);
DrawOctagon(hDC, RGB(255, 0, 0), x, squareY + squareSize - h, w, h);
Sleep(30);
}
// Движение вверх
for (int y = squareY + squareSize - h; y >= squareY; y -= 5)
{
DrawOctagon(hDC, bg, squareX, y + 5, w, h);
DrawOctagon(hDC, RGB(255, 0, 0), squareX, y, w, h);
Sleep(30);
}
cin.get();
return 0;
}