#include "myWin.h" #include "math.h" #define PI 3.14159265358979 static double curX, curY, Theta; void t_pos(double X, double Y){ curX = X; curY = Y;} void t_deg (double T){ Theta = T;} void t_turn(double T){ Theta += T;} void t_forward(HDC hdc,double length){ double TH = Theta * PI / 180; double X = curX+length*cos(TH); double Y = curY+length*sin(TH); MoveToEx(hdc,(int)curX, 100 -(int)curY, NULL); LineTo (hdc,(int) X, 100 -(int) Y); curX=X; curY=Y; } void koch(HDC hdc,int n, double length){ if(n<=0) { t_forward(hdc,length); return; } int nn=n -1;double len=length/3; koch(hdc,nn,len);t_turn( 60); koch(hdc,nn,len);t_turn(-120); koch(hdc,nn,len);t_turn( 60); koch(hdc,nn,len); } void procPaint(HWND hw, WPARAM wp,LPARAM lp){ PAINTSTRUCT ps; HDC hdc=BeginPaint(hw, &ps); t_pos(0,0); t_deg(0); koch(hdc,5,300); EndPaint(hw,&ps); } void procCreate(HWND hw, WPARAM wp,LPARAM lp){ SetWindowText(hw,TEXT("ƒRƒbƒz‹Èü")); MoveWindow(hw,0,0,300,200,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); }