无聊,画一个五角星玩玩
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);
}
};