无聊画一个五角星玩玩

无聊,画一个五角星玩玩

code      https://github.com/char0xface/five_pointed_star

EXE 链接:https://pan.baidu.com/s/1ffD8DUqtp3P3lqdHoHkkNw 
提取码:9p1b 
 

class   FIVESTAR
{
private:
    HWND hwnd;
    int radius;
    int color_red,color_green,color_blue;
    int  direction;
    int speed;
public:

    FIVESTAR( int  dir,int diameter,int red=0,int green=0,int blue=0,int sp=1)
    {
        speed=sp;
        radius=diameter/2;
        direction=dir;
        color_red=red;
        color_green=green;
        color_blue=blue;
    }

    unsigned int draw()
    {
        POINT pt0= {radius,radius};
        float step=0;
        float twopi=2*3.1415926;
        float delta=twopi/5.0;
        int order[]= {0,2,4,1,3,0};
        POINT pt[6];
        COLORREF  rgb=0;
        DWORD t0=GetTickCount();
        int t=0;
        srand(GetTickCount());
        while(true)
        {
            Sleep(3);
            if(GetTickCount()-t0>15)
            {

                HDC hdc=GetDC(hwnd);
                HDC hmem=CreateCompatibleDC(hdc);
                HBITMAP hbmp=CreateCompatibleBitmap(hdc,radius*3,radius*3);
                SelectObject(hmem,hbmp);

                if(t%500==0)
                {
                    if(color_red!=0 || color_green!=0 || color_blue!=0) rgb=RGB(color_red,color_green,color_blue);
                    else    rgb=RGB((rand()%255)+1,(rand()%255)+1,(rand()%255)+1);
                }
                t++;

                step+=0.012*speed*direction;
                if(step>twopi)step-=twopi;
                for(unsigned int i=0; i<sizeof(order)/sizeof(*order); i++)
                {
                    float dt= delta*order[i]+step;
                    pt[i].x=pt0.x+radius*cos(dt);
                    pt[i].y=pt0.y+radius*sin(dt);
                }
                //HPEN  hpen=CreatePen(PS_DASH,0,rgb);
                HPEN  hpen=CreatePen(PS_SOLID,2,rgb);
                SelectObject(hmem,hpen);
                Polyline(hmem,pt,sizeof(order)/sizeof(*order));
                BitBlt(hdc,0,0,radius*3,radius*3,hmem,0,0,SRCCOPY	);

                DeleteObject(hpen);
                DeleteObject(hbmp);
                DeleteDC(hmem);
                ReleaseDC(hwnd,hdc);
                t0=GetTickCount();
            }
        }
        return 0;
    }

    static unsigned int __stdcall mythread(void* p)
    {
        return   ((FIVESTAR* )p)->draw();;
    }
    void show(HWND hw)
    {
        hwnd=hw;
        HANDLE h = (HANDLE)_beginthreadex(NULL, 0,FIVESTAR:: mythread, this, 0, NULL);
        CloseHandle(h);
    }
};

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值