#include "myWin.h" #include "math.h" #define ORDER 5 // 次数(dimension) #define INIT_H 10 // Hの初期値(initial value of H) #define SX 20 // 画面左上端座標(screen top/left coordinate) #define RSC 1 // 画面表示倍率の逆数(reverse value of screen scale) int cX, cY, ID, H; void pos(int X, int Y){ cX = X; cY = Y;} int ScXY(int X){ return SX + X/RSC; } void rLine(HDC hdc, double X, double Y){//相対描画(relatively draw line) int nX = cX + X, nY = cY + Y; MoveToEx(hdc, ScXY(cX), ScXY(cY), NULL); LineTo (hdc, ScXY(nX), ScXY(nY)); cX=nX; cY=nY; } void URD(HDC hdc); void LDR(HDC hdc); void DLU(HDC hdc); void RUL(HDC hdc){ if(ID<=0) return; ID--; URD(hdc); rLine(hdc, H, 0); RUL(hdc); rLine(hdc, 0, H); RUL(hdc); rLine(hdc, -H, 0); DLU(hdc); ID++; } void DLU(HDC hdc){ if(ID<=0) return; ID--; LDR(hdc); rLine(hdc, 0, -H); DLU(hdc); rLine(hdc, -H, 0); DLU(hdc); rLine(hdc, 0, H); RUL(hdc); ID++; } void LDR(HDC hdc){ if(ID<=0) return; ID--; DLU(hdc); rLine(hdc, -H, 0); LDR(hdc); rLine(hdc, 0, -H); LDR(hdc); rLine(hdc, H, 0); URD(hdc); ID++; } void URD(HDC hdc){ if(ID<=0) return; ID--; RUL(hdc); rLine(hdc, 0, H); URD(hdc); rLine(hdc, H, 0); URD(hdc); rLine(hdc, 0, -H); LDR(hdc); ID++; } void procPaint(HWND hw, WPARAM wp,LPARAM lp){ PAINTSTRUCT ps; HDC hdc=BeginPaint(hw, &ps); pos(0,0); ID = ORDER; H = INIT_H; RUL(hdc); EndPaint(hw,&ps); } void procCreate(HWND hw, WPARAM wp,LPARAM lp){ SetWindowText(hw,TEXT("Hilbert Curve")); MoveWindow(hw,0,0,380,400,TRUE); } LRESULT CALLBACK WndProc(HWND hw, UINT msg, WPARAM wp,LPARAM lp){ switch(msg){ case WM_DESTROY : PostQuitMessage(0) ; return 0; case WM_CREATE : procCreate(hw,wp,lp) ; return 0; case WM_PAINT : procPaint(hw,wp,lp) ; return 0; } return DefWindowProc(hw,msg,wp,lp); }