zoukankan      html  css  js  c++  java
  • 随正弦曲线改变的圆

    //windows.h文件中包含应用程序中所需的数据类型和数据结构的定义
    #include <windows.h>
    #include <stdlib.h>
    #include <time.h>
    #include <math.h>
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//窗口函数说明
    //---------以下初始化窗口类--------------
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
    {
        HWND hwnd;
        MSG Msg;
        WNDCLASS wndclass;
        char lpszClassName[] = "窗口";     //窗口类名
        char lpszTitle[] = "My_Windows";    //窗口标题名
    
        //窗口类的定义
        wndclass.style = CS_HREDRAW | CS_VREDRAW;                  //窗口类型为默认类型
        wndclass.lpfnWndProc = WndProc;      //窗口处理函数为WndProc
        wndclass.cbClsExtra = 0;             //窗口类无扩展
        wndclass.cbWndExtra = 0;             //窗口实例无扩展
        wndclass.hInstance = hInstance;     //当前实例句柄
    
        wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);//窗口的最小化图标为默认图标
        wndclass.hCursor = LoadCursor( NULL, IDC_ARROW); //窗口 采用箭头光标
        wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //窗口 背景为 白色
        wndclass.lpszMenuName = NULL ; //窗口 中无菜单
        wndclass.lpszClassName = lpszClassName; //窗口类名为“窗口示例”
    //-----------以下进行窗口类的注册
        if (!RegisterClass(&wndclass))//如果注册失败则发出警吿声音
        {
            MessageBeep (0);
            return FALSE;
        }
    
    //创建窗口
        hwnd = CreateWindow(
                            lpszClassName, //窗口类名
                            lpszTitle,      //窗口实例的标题名
                            WS_OVERLAPPEDWINDOW, //窗口 的风格
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,  //窗口左上角坐标为默认值
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,  //窗口的髙和宽为默认值
                            NULL,           //此窗口无父窗口
                            NULL,           //此窗口无主菜单
                            hInstance,      //创建此窗口应用程序的当前句柄
                            NULL            //不使用该值
                            );
    
    
    
        ShowWindow( hwnd, nCmdShow);        //显示窗口
        UpdateWindow(hwnd);                 //绘制用户区
        while( GetMessage(&Msg, NULL, 0, 0)) //消息循环
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;                  //程序终止时将信息返回系统
    }
    #define LR (rect.left+rect.right)
    #define TD (rect.bottom+rect.top)
    #define I (i>100)?(200-i):(i)
    #define PI acos(-1)
    double A = 100.0;
    double W = 60.0;
    //窗口函数
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC hDC;
        HBRUSH hBrush;
        RECT rect;
        HPEN hPen;
        PAINTSTRUCT PtStr;
        POINT p[100];
        static int i = 0;
        LONG R = 0;
        COLORREF color[7] = {RGB(255,0,0), RGB(255,165,0), RGB(255,255,0), RGB(0,255,0), RGB(0,255,255), RGB(0,0,255), RGB(139,0,255)};
    
        for (int i = 0; i < 100; i++)
        {
            p[i].x = (LONG)2*PI*i/100*W +200;
            p[i].y = (LONG)A*sin(2*PI/100*i) + 200;
        }
    
        switch(message)
        {
        case WM_PAINT:
            GetClientRect(hWnd, &rect);
    
            hDC = BeginPaint(hWnd, &PtStr);
            //SetWindowOrgEx(hDC, -200,-200,NULL);
            hPen = CreatePen(PS_SOLID, 3, color[0]);
            SelectObject(hDC, hPen);
            Polyline(hDC, p, 100);
            DeleteObject(hPen);
    
            if (i <= 25)
            {
                hPen = CreatePen(PS_SOLID, 3, color[0]);
                hBrush = CreateHatchBrush(HS_BDIAGONAL, color[0]);
                R = i*A/62.5 + 0.2*A;
            }
            else if (i <= 50)
            {
                hPen = CreatePen(PS_SOLID, 3, color[1]);
                hBrush = CreateHatchBrush(HS_CROSS, color[1]);
                R = 0.6*A-(i-25)*A/62.5;
            }
            else if (i <= 75)
            {
                hPen = CreatePen(PS_SOLID, 3, color[2]);
                hBrush = CreateHatchBrush(HS_DIAGCROSS, color[2]);
                R = (i-50)*A/62.5 + 0.2*A;
            }
            else if (i <= 100)
            {
                hPen = CreatePen(PS_SOLID, 3, color[3]);
                hBrush = CreateHatchBrush(HS_FDIAGONAL, color[3]);
                R = 0.6*A-(i-75)*A/62.5;
            }
            else if (i <=200 && i >175)
            {
                hPen = CreatePen(PS_SOLID, 3, color[2]);
                hBrush = CreateHatchBrush(HS_CROSS, color[2]);
                R = 0.6*A-(i-175)*A/62.5;
            }
            else if (i <= 175 && i >150)
            {
                hPen = CreatePen(PS_SOLID, 3, color[1]);
                hBrush = CreateHatchBrush(HS_FDIAGONAL, color[1]);
                R = (i-150)*A/62.5 + 0.2*A;
            }
            else if (i <= 150 && i > 125)
            {
                hPen = CreatePen(PS_SOLID, 3, color[3]);
                hBrush = CreateHatchBrush(HS_DIAGCROSS, color[3]);
                R = 0.6*A-(i-125)*A/62.5;
            }
            else if(i <= 125 && i > 100)
            {
                hPen = CreatePen(PS_SOLID, 3, color[0]);
                hBrush = CreateHatchBrush(HS_BDIAGONAL, color[0]);
                R = (i-100)*A/62.5 + 0.2*A;
            }
    
            SelectObject(hDC, hPen);
            SelectObject(hDC, hBrush);
            Ellipse(hDC, p[I].x-R, p[I].y-R, p[I].x+R, p[I].y+R);
            DeleteObject(hPen);
            DeleteObject(hBrush);
            Sleep(100);
            if (i == 200)
                i = 0;
            ++i;
            InvalidateRect(hWnd, NULL, 1);
    
            EndPaint(hWnd, &PtStr);
    
            return 0;
    
        case WM_DESTROY:
            PostQuitMessage(0);                 //调用 PostQuitMessage 发出 WM_QUIT 消息
            return 0;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam); //默认时采用系统消息默认处理函数
    
        }
    
    }
  • 相关阅读:
    Unity Shader入门精要之 screen post-processing effect
    Unity---关于游戏小包的记录
    计算机基础补充之原码、反码、补码
    C#接口实现技巧之借助第三方
    lua中产生 1
    游戏文本本地化(一)
    xlua修复C#的委托事件的时候,需要提前做好配置
    xlua 实现协程替换Unity中的协程
    C#定义只能处理枚举类型的泛型类型
    C# : 泛型的继承关系实现的一个可以存放不同数据类型的链表
  • 原文地址:https://www.cnblogs.com/Vikyanite/p/12453852.html
Copyright © 2011-2022 走看看