c语言阿基米德螺旋线编程,阿基米德螺旋线

c语言阿基米德螺旋线编程,阿基米德螺旋线这段代码示例展示了如何利用 OpenGL 在 Windows 环境下绘制一个动态变化的螺旋图形

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include 

#include 

const char g_szClassName[] = "Example";

const char g_szCaption[] = "Archimedes\' Screw";

const int ID_TIMER1 = 1,

&nbsp&nbsp&nbsp nScreenWidth = GetSystemMetrics(SM_CXSCREEN),

&nbsp&nbsp&nbsp nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

&nbsp&nbsp&nbsp static bool flag = false;

&nbsp&nbsp&nbsp static double max_theta = 0;

&nbsp&nbsp&nbsp static PAINTSTRUCT ps;

&nbsp&nbsp&nbsp static HDC hDC, mDC;

&nbsp&nbsp&nbsp switch (msg)

&nbsp&nbsp&nbsp {

&nbsp&nbsp&nbsp case WM_PAINT:

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp hDC = BeginPaint(hWnd, &ps);

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp for (double theta = 0; theta 

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp SetPixel(hDC, nScreenWidth/2+10*cos(theta)*theta, nScreenHeight/2+10*sin(theta)*theta, RGB(255,0,0));

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp UpdateWindow(hWnd);

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp EndPaint(hWnd, &ps);

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp return 0;

&nbsp&nbsp&nbsp case WM_TIMER:

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp if (!flag)

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp {

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp if (max_theta 

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp {

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp max_theta += 5;

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp InvalidateRect(hWnd, NULL, TRUE);

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp }

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp else flag = true;

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp }

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp else if (max_theta > 0)

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp {

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp max_theta -= 5;

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp InvalidateRect(hWnd, NULL, TRUE);

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp }

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp else KillTimer(hWnd, ID_TIMER1);

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp return 0;

&nbsp&nbsp&nbsp case WM_DESTROY:

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp PostQuitMessage(0);

&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp return 0;

&nbsp&nbsp&nbsp }

&nbsp&nbsp&nbsp return DefWindowProcA(hWnd, msg, wParam, lParam);

}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{

&nbsp&nbsp&nbsp WNDCLASSA wc;

&nbsp&nbsp&nbsp HWND hWnd;

&nbsp&nbsp&nbsp MSG msg;

&nbsp&nbsp&nbsp wc.style&nbsp &nbsp &nbsp &nbsp  = 0;

今天的文章 c语言阿基米德螺旋线编程,阿基米德螺旋线分享到此就结束了,感谢您的阅读。
编程小号
上一篇 2025-01-02 17:30
下一篇 2025-01-02 17:27

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/99556.html