// PROGRAM site2 // サイト・パーコレーションの配置を描画 #include "TrueBASIC.h" #include "csgraphics.h" int main(); void initial(double rsite[][65], int *L, double *p, double *delta_p, int* mrk); void configuration(double rsite[][65], int L, double *p, double delta_p, int site[][65], int np[], int mrk); void assign(int site[][65], int np[], int L); void neighbor(int site[][65], int np[], int x, int y); void label_min(int site[][65], int np[], int x, int y, int left, int down); int proper(int np[], int label); void show_label(int site[][65], int np[], int L, char* properlabel); void span(int site[][65], int *vspan, int L); int main() { int L, site[65][65], np[1001], mrk, Itmp1_, Itmp2_; double delta_p, p, rsite[65][65]; for(Itmp1_ = 0; Itmp1_ < 65; ++Itmp1_) for(Itmp2_ = 0; Itmp2_ < 65; ++Itmp2_) site[Itmp1_][Itmp2_] = 0; GWopen(0); // 格子とスクリーンのパラメータを指定 initial(rsite, &L, &p, &delta_p, &mrk); // 与えられた確率 p で格子点を占有する configuration(rsite, L, &p, delta_p, site, np, mrk); GWquit(); return 0; } void initial(double rsite[][65], int *L, double *p, double *delta_p, int* mrk) { int x, y; float xwin, ywin; char Stmp1_[_LBUFF_]; rnd(-1); GWinput("linear dimension of square lattice = ", Stmp1_, _LBUFF_); sscanf(Stmp1_, "%d", L); GWinput("initial probability p = ", Stmp1_, _LBUFF_); sscanf(Stmp1_, "%lg", p); // マウスがクリックされたときに与える p の増分 GWinput("delta p = ", Stmp1_, _LBUFF_); sscanf(Stmp1_, "%lg", delta_p); compute_aspect_ratio((float)(*L), &xwin, &ywin); GWindow(-0.1f*xwin, -0.1f*ywin, xwin, ywin); GWsetpen(BLACK, -1, -1, 4); GWsetbrs(-1, 0, -1); *mrk = GWcmbmrk(0, 5, 1.0f, YELLOW, -1, 4); GWanchor(1); for(y = 1; y <= (*L); ++y) // 格子点を描画する { for(x = 1; x <= (*L); ++x) { // 各格子点に乱数を割り当てる rsite[x][y] = rnd(0); } } } void configuration(double rsite[][65], int L, double *p, double delta_p, int site[][65], int np[], int mrk) { int vspan = 0, x, y; float xs = 1, ys; char Stmp1_[_LBUFF_]; GWsetogn(0, -2); while((*p) <= 1) { sprintf(Stmp1_, "p = %f", (*p)); GWsettxt(L/25.0f, 0.0f, 1, 0, -1, NULL); GWputtxt(0.0f, (float)(L+1), Stmp1_); GWsettxt(0.6f, 0.0f, 0, 0, -1, NULL); for(y = 1; y <= L; ++y) for(x = 1; x <= L; ++x) if(rsite[x][y] < (*p)) { site[x][y] = -1; GWputcmb(mrk, (float)x, (float)y, 0.0f, 0.0f, 0); } GWrect(0.5f, 0.5f, L+0.5f, L+0.5f); // 線を再び描画する assign(site, np, L); show_label(site, np, L, "yes"); span(site, &vspan, L); GWflush(-2); GWcappnt(&xs, &ys, NULL); if(xs < 0.0f) return; (*p) += delta_p; } }