// ■地形図生成 #include "myWin.h" #include "math.h" #include "stdlib.h" #include "time.h" #define MX 512 #define frand() ((double) rand()/(double)(RAND_MAX+1)) static HDC hBuff; static HBITMAP hBM; double map[MX+1][MX+1]; void setMap(int L, int U, int W, double dH){ if(W<2)return; int WW = W / 2; map[L+WW][U ] = (map[L+W ][U ]+map[L][U ])*0.5+dH*(frand()-0.5); map[L+WW][U+W ] = (map[L+W ][U+W]+map[L][U+W])*0.5+dH*(frand()-0.5); map[L ][U+WW] = (map[L ][U ]+map[L][U+W])*0.5+dH*(frand()-0.5); map[L+W ][U+WW] = (map[L+W ][U+W]+map[L+W][U])*0.5+dH*(frand()-0.5); map[L+WW][U+WW] = (map[L+WW][U]+map[L+WW][U+W]+map[L][U+WW]+map[L+W][U+WW])*0.25 +dH*(frand()-0.5); setMap(L ,U ,WW,dH*0.9); setMap(L+WW,U ,WW,dH*0.9); setMap(L ,U+WW,WW,dH*0.9); setMap(L+WW,U+WW,WW,dH*0.9); } void setMap(){ setMap(0,0, MX,10); for(int k=0;k<50;k++) for(int i=1;iR) R=map[i][j]; return R; } void draw(){ double V1=minZ(), V2=maxZ(); if(abs(V2-V1)<0.000001) V2=V1+1; double DD=(V2-V1)/768;int C; for(int i=1;i