#include "myWin.h" #include "math.h" #include "stdio.h" #include "stdlib.h" #define BITX 400 #define BITY 400 static HDC hbuf; static HBITMAP hBM; void initBitMap(HWND hw){ HDC hdc=GetDC(hw); hBM=CreateCompatibleBitmap(hdc,BITX,BITY); hbuf=CreateCompatibleDC(hdc);SelectObject(hbuf,hBM); SelectObject(hbuf,GetStockObject(NULL_PEN)); ReleaseDC(hw, hdc); } void clearBitmap(){ PatBlt(hbuf,0,0,BITX,BITY,WHITENESS); } #define PI 3.1415926535897932385 #define SEP1(X) ((X>>16) & 0xFF) #define SEP2(X) ((X>>8) & 0xFF) #define SEP3(X) (X & 0xFF) int check=1;//check=1のとき1周期分の計算結果で描画 double k=0.1,B=12, DT=0.008,DB=0.01; int NSEP=800; void strDbl(double A, TCHAR str[]){ char tmp[256];int i; sprintf(tmp, "%7.4lf", A); for(i=0; tmp[i]!=0; i++) str[i]=tmp[i]; str[i]=0; } void strDsp(TCHAR name[], double A, TCHAR str[]){ int i; for(i=0; name[i]!=0; i++) str[i]=name[i]; strDbl(A, &str[i]); } void dspValue(){ TCHAR str[256]; HFONT hf=CreateFont(12,0,0,0,FW_NORMAL,FALSE, FALSE, FALSE, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH|FF_MODERN, NULL); SelectObject(hbuf,hf); TEXTMETRIC tm;GetTextMetrics(hbuf, &tm);int h=tm.tmHeight; SetTextColor(hbuf,0); SetBkMode(hbuf,TRANSPARENT); strDsp(TEXT("B = "), B, str); TextOut(hbuf,20, 20 ,str,lstrlen(str)); DeleteObject(hf); } int intX(double X) {return (int)(X * 40 + 200.5);} int intY(double X) {return (int)(200.5-X * 10);} void drawPic(double X, double Y, int i){ SetPixel(hbuf, intX(X),intY(Y), RGB(SEP1(i), SEP2(i), SEP3(i))); } void cmpIter(){ clearBitmap(); dspValue(); double T=0, X = 0.2, Y = 0.1,XN , YN ,DX, DY; for(int j=0;j<8000;j++){ for(int i = 0; i200) drawPic(X, Y, j * 127); //drawPic(X, Y, j * 127); } } void procLButtonDown(HWND hw, WPARAM wp, LPARAM lp){ cmpIter(); InvalidateRect(hw,NULL,FALSE); } void procCreate(HWND hw, WPARAM wp, LPARAM lp){ MoveWindow(hw,0,0,BITX,BITY,NULL); SetWindowText(hw,TEXT("Japanese Attractor")); initBitMap(hw); k=0.1,B=11.5, DT = 2 * PI / NSEP; SetTimer(hw,1,10,NULL); procLButtonDown(hw,wp,lp); } void procTimer(HWND hw, WPARAM wp, LPARAM lp){// ビットマップを画面に表示 if(abs(B-12)<0.0000001) KillTimer(hw,1); else { B+=DB; procLButtonDown(hw,wp,lp); } } void procPaint(HWND hw, WPARAM wp, LPARAM lp){// ビットマップを画面に表示 PAINTSTRUCT ps; HDC hdc=BeginPaint(hw, &ps); BitBlt(hdc,0,0,BITX,BITY,hbuf,0,0,SRCCOPY); EndPaint(hw,&ps); } 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_TIMER : procTimer(hw,wp,lp) ; return 0; case WM_LBUTTONDOWN : procLButtonDown(hw,wp,lp) ; return 0; case WM_PAINT : procPaint (hw, wp, lp); return 0; } return DefWindowProc(hw, msg, wp, lp); }