// PROGRAM site // サイト・パーコレーションの配置を描画 #include "TrueBASIC.h" #include "csgraphics.h" int main(); void initial(double rsite[][65], int *L, double *p, double *delta_p, int *occup); void configuration(double rsite[][65], int L, double *p, double delta_p, int occup); int main() { int L, occup; double delta_p, p, rsite[65][65]; GWopen(0); // 格子とスクリーンのパラメータを指定 initial(rsite, &L, &p, &delta_p, &occup); // 与えられた確率 p で格子点を占有する configuration(rsite, L, &p, delta_p, occup); GWquit(); return 0; } void initial(double rsite[][65], int *L, double *p, double *delta_p, int *occup) { int x, y; double r; float xwin, ywin, pix, piy; char Stmp1_[_LBUFF_]; rnd(-1); printf("linear dimension of square lattice = "); fgets(Stmp1_, _LBUFF_, stdin); sscanf(Stmp1_, "%d", L); printf("initial probability p = "); fgets(Stmp1_, _LBUFF_, stdin); sscanf(Stmp1_, "%lg", p); // マウスがクリックされたときに与える p の増分 printf("delta p = "); fgets(Stmp1_, _LBUFF_, stdin); sscanf(Stmp1_, "%lg", delta_p); compute_aspect_ratio((float)(*L), &xwin, &ywin); GWindow(-0.1f*xwin, -0.1f*ywin, xwin, ywin); GWsetpen(BLUE, -1, -1, 4); // 占有された格子点を直径が単位長さの青色の円で示す GWpxlsiz(&pix, &piy); *occup = GWcmbmrk(1, 6, 1 + 2*piy, BLUE, -1, 4); GWsetpen(BLACK, -1, -1, 4); r = 0.5; GWrect((float)(1-r), (float)(1-r), (float)((*L)+r), (float)((*L)+r)); for(y = 1; y <= (*L); ++y) // 格子点を描画する { for(x = 1; x <= (*L); ++x) { // 各格子点に乱数を割り当てる rsite[x][y] = rnd(0); GWsetpxl((float)(x), (float)(y), BLACK); } } GWanchor(1); } void configuration(double rsite[][65], int L, double *p, double delta_p, int occup) { int x, y; float xs = 1, ys; char Stmp1_[_LBUFF_]; while((*p) <= 1) { GWsetogn(0, -10); sprintf(Stmp1_, "p = %f", (*p)); GWputtxt(0.0f, (float)(L+1), Stmp1_); for(y = 1; y <= L; ++y) for(x = 1; x <= L; ++x) if(rsite[x][y] < (*p)) GWputcmb(occup, (float)x, (float)y, 0.0f, 0.0f, 0); GWflush(-10); GWsetogn(0, 2); GWsetbrs(RED, 1, -1); do { GWcappnt(&xs, &ys, NULL); if(xs < 0.0f) return; // クラスターを見るためには占有された格子点をクリック // p を delta_p だけ増やすためには格子の右側でマウスをクリック if(xs < L+0.5 && xs > -0.5 && ys < L+0.5 && ys > -0.5) { GWflood(xs, ys); } } while(xs < L+0.5); (*p) += delta_p; GWerase(2, -1); } }