Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <windows.h>
- #include <cmath>
- int w = 800;
- int h = 600;
- sf::RenderWindow window;
- LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- break;
- }
- case WM_CLOSE:
- {
- DestroyWindow(hwnd);
- break;
- }
- case WM_PAINT:
- {
- int b, c, nw, nh;
- double i, m, x1, y1, x2, y2, l, a, z;
- sf::Vertex vertices[2];
- RECT ClientRect;
- GetClientRect(hwnd, &ClientRect);
- nw = ClientRect.right - ClientRect.left;
- nh = ClientRect.bottom - ClientRect.top;
- sf::View NewView;
- NewView.setSize(nw, nh);
- NewView.setCenter(nw / 2, nh / 2);
- window.setView(NewView);
- window.clear(sf::Color(255, 255, 255));
- z = 5.0;
- a = (nh / 2) - 20;
- l = nw / z;
- i = l / 360.0;
- m = nh / 2;
- x1 = 0;
- y1 = 0;
- for(b = 0; b < z; b++)
- {
- for(c = 0; c < 360; c++)
- {
- x2 = x1 + i;
- y2 = std::sin((x2 / i) * (M_PI / 180.0)) * a;
- vertices[0] = sf::Vertex(sf::Vector2f(x1, y1 + m), sf::Color(0, 0, 0));
- vertices[1] = sf::Vertex(sf::Vector2f(x2, y2 + m), sf::Color(0, 0, 0));
- window.draw(vertices, 2, sf::Lines);
- x1 = x2;
- y1 = y2;
- }
- }
- window.display();
- break;
- }
- default:
- {
- return DefWindowProc(hwnd, message, wParam, lParam);
- }
- }
- return 0;
- }
- INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- MSG message;
- WNDCLASS w;
- HWND port, wnd;
- w.style = 0;
- w.lpfnWndProc = &WinProc;
- w.cbClsExtra = 0;
- w.cbWndExtra = 0;
- w.hInstance = hInstance;
- w.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- w.hCursor = LoadCursor(NULL, IDC_ARROW);
- w.hbrBackground = NULL;
- w.lpszMenuName = NULL;
- w.lpszClassName = "Sine Wave";
- if(!RegisterClass(&w))
- {
- return 1;
- }
- wnd = CreateWindow(
- "Sine Wave",
- "Sine Wave Generator (Caelan Stewart)",
- WS_OVERLAPPEDWINDOW,
- 50, 50,
- 800, 600,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- if(wnd == NULL)
- {
- return 1;
- }
- ShowWindow(wnd, nCmdShow);
- UpdateWindow(wnd);
- window.create(wnd);
- while(GetMessage(&message, NULL, 0, 0) > 0)
- {
- TranslateMessage(&message);
- DispatchMessage(&message);
- }
- return message.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement