Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Proudly made by ayangd :p
- #include <windows.h>
- #include <windowsx.h>
- #include <math.h>
- #include <gdiplus.h>
- #include <ctime>
- using namespace Gdiplus;
- using namespace std;
- typedef struct {
- double x;
- double y;
- } Vector;
- #define SCREEN_WIDTH 640
- #define SCREEN_HEIGHT 480
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- void updateWindow(HWND hWnd);
- int WINAPI WinMain(HINSTANCE hInst, HINSTANCE prevHInst, LPSTR cmdLine, int nShowCmd) {
- HWND hWnd;
- GdiplusStartupInput gdiplusStartupInput;
- ULONG_PTR gdiplusToken;
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- WNDCLASSEX wc;
- ZeroMemory(&wc, sizeof(WNDCLASSEX));
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = hInst;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
- wc.lpszClassName = "WindowBalok";
- RegisterClassEx(&wc);
- RECT wr = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
- AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
- hWnd = CreateWindowEx(0, // Previously NULL, but compiler complains
- "WindowBalok",
- "Kubus",
- WS_OVERLAPPEDWINDOW,
- 100,
- 100,
- wr.right - wr.left,
- wr.bottom - wr.top,
- NULL,
- NULL,
- hInst,
- NULL);
- ShowWindow(hWnd, nShowCmd);
- MSG msg;
- clock_t clocking = clock();
- clock_t newClocking;
- while (TRUE) {
- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if (msg.message == WM_QUIT)
- break;
- }
- newClocking = clock();
- if (newClocking - clocking > (double) CLOCKS_PER_SEC / 60) {
- RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
- clocking += (double) CLOCKS_PER_SEC / 60;
- }
- // Sleep(1000 / 60);
- }
- GdiplusShutdown(gdiplusToken);
- return msg.wParam;
- }
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
- switch (message) {
- case WM_PAINT:
- updateWindow(hWnd);
- return 0;
- case WM_ERASEBKGND:
- return TRUE;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- void drawCube(Graphics *graph, Pen *pen, int centerX, int centerY, int scale, double rotation) {
- static Vector corner[4];
- static Vector cornerOff[5][4];
- int i;
- for (i = 0; i < 4; i++) {
- corner[i].x = cos(rotation + (3.14 / 2) * i);
- corner[i].y = sin(rotation + (3.14 / 2) * i) / 4;
- corner[i].x *= (double) scale / 120;
- corner[i].y *= (double) scale / 120;
- }
- graph->DrawLine(pen, (int)(centerX + 100 * corner[0].x), centerY + 100 * corner[0].y - scale / 2, centerX + 100 * corner[3].x, centerY + 100 * corner[3].y - scale / 2);
- graph->DrawLine(pen, (int)(centerX + 100 * corner[0].x), centerY + 100 * corner[0].y + scale / 2, centerX + 100 * corner[3].x, centerY + 100 * corner[3].y + scale / 2);
- for (i = 0; i < 4; i++) {
- if (i != 0)
- graph->DrawLine(pen, (int)(centerX + 100 * corner[i-1].x), centerY + 100 * corner[i-1].y - scale / 2, centerX + 100 * corner[i].x, centerY + 100 * corner[i].y - scale / 2);
- if (i != 0)
- graph->DrawLine(pen, (int)(centerX + 100 * corner[i-1].x), centerY + 100 * corner[i-1].y + scale / 2, centerX + 100 * corner[i].x, centerY + 100 * corner[i].y + scale / 2);
- graph->DrawLine(pen,
- (int)(centerX + 100 * corner[i].x),
- (int)(centerY + 100 * corner[i].y) - scale / 2,
- (int)(centerX + 100 * corner[i].x),
- (int)(centerY + 100 * corner[i].y) + scale / 2);
- }
- }
- void updateWindow(HWND hWnd) {
- static HDC hdc;
- static PAINTSTRUCT ps;
- hdc = BeginPaint(hWnd, &ps);
- static Bitmap bmp(SCREEN_WIDTH, SCREEN_HEIGHT);
- static Graphics* graphics = Graphics::FromImage(&bmp);
- graphics->Clear(Color(255, 0, 0, 0));
- static Pen pen(Color(255, 63, 255, 63));
- static double spin = 0; spin += 0.01;
- int i;
- for (i = 0; i < 20; i++) {
- drawCube(graphics, &pen, (SCREEN_WIDTH / 2) + (cos(spin + (3.14 * 2) * i / 20) * 200), (SCREEN_HEIGHT / 2) + (sin(spin + (3.14 * 2) * i / 20) * 200), 30, -3.14 / 2 + (spin + (3.14 / 64) * i));
- }
- drawCube(graphics, &pen, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 120, -3.14 / 2 + spin);
- drawCube(graphics, &pen, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + (int)(sin(spin * 1) * 30), 60, -3.14 / 2 + spin * 2);
- drawCube(graphics, &pen, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + (int)(sin(spin * 2) * 45), 30, -3.14 / 2 + spin * 3);
- drawCube(graphics, &pen, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + (int)(sin(spin * 3) * 52), 15, -3.14 / 2 + spin * 4);
- drawCube(graphics, &pen, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + (int)(sin(spin * 4) * 55), 7, -3.14 / 2 + spin * 5);
- FontFamily fontFamily(L"Consolas");
- Font font(&fontFamily, 12);
- SolidBrush brush(Color(255, 63, 255, 63));
- static int dots = 0; dots = (dots + 1) % 60;
- graphics->DrawString((dots < 20) ? L"Loading." : (dots < 40) ? L"Loading.." : L"Loading...", -1, &font, PointF(SCREEN_WIDTH / 2 - 45, SCREEN_HEIGHT * 29 / 40), &brush);
- Graphics realGraph(hdc);
- realGraph.DrawImage(&bmp, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
- DeleteObject(&bmp);
- EndPaint(hWnd, &ps);
- DeleteObject(&hdc);
- DeleteObject(&ps);
- DeleteObject(&pen);
- }
Advertisement
Add Comment
Please, Sign In to add comment