// PROGRAM rg #include "TrueBASIC.h" #include "csgraphics.h" int main(); void initial(double r[][33], int *L, int *b, int *IC1_, int *IC2_, int *IC3_, int *IC4_); void lattice(int Ln); void configuration(double r[][33], int L, int b, int IC1_, int IC2_, int IC3_, int IC4_); void block(int IC9_, int Ln, double w[][33], double wr[][33]); int main() { int b, L, IC1_ = 1, IC2_ = 2, IC3_ = 3, IC4_ = 4; double r[33][33]; GWopen(0); initial(r, &L, &b, &IC1_, &IC2_, &IC3_, &IC4_); configuration(r, L, b, IC1_, IC2_, IC3_, IC4_); GWquit(); return 0; } void initial(double r[][33], int *L, int *b, int *IC1_, int *IC2_, int *IC3_, int *IC4_) { int x, y; rnd(-1); (*L) = 32; // b <> 2 についてはプログラムを修正する必要がある (*b) = 2; // 各格子点に乱数を割り振る for(y = 1; y <= (*L); ++y) { for(x = 1; x <= (*L); ++x) { r[x][y] = rnd(0); } } GWvport(0.0f, 0.5f, 0.5f*GWaspect(1), 1.0f); lattice(*L); // ウィンドウ #1 に元の格子を描く GWsavevp(*IC1_); GWvport(0.5f*GWaspect(1), 0.5f, GWaspect(1), 1.0f); lattice((*L)/(*b)); GWsavevp(*IC2_); GWvport(0.0f, 0.0f, 0.5f*GWaspect(1), 0.5f); lattice((*L)/((*b)*(*b))); GWsavevp(*IC3_); GWvport(0.5f*GWaspect(1), 0.0f, GWaspect(1), 0.5f); lattice((*L)/((*b)*(*b)*(*b))); GWsavevp(*IC4_); GWanchor(1); } void lattice(int Ln) { int x, y; float xwin, ywin; char Stmp1_[_LBUFF_]; compute_aspect_ratio((float)Ln, &xwin, &ywin); GWindow(-0.07f*xwin, -0.07f*ywin, 1.07f*xwin, 1.07f*ywin); GWrect(0.0f, 0.0f, (float)(Ln), (float)(Ln)); sprintf(Stmp1_, "L = %d", Ln); GWputtxt(0.0f, ywin, Stmp1_); for(y = 1; y <= Ln; ++y) for(x = 1; x <= Ln; ++x) GWsrect((float)(x - 0.45), (float)(y - 0.45), (float)(x - 0.55), (float)(y - 0.55), BLUE); } void configuration(double r[][33], int L, int b, int IC1_, int IC2_, int IC3_, int IC4_) { int x, y; double p = 0, s[33][33], s1[17][33], s2[9][33], s3[5][33]; char Stmp1_[_LBUFF_]; while(p <=1) { GWselvp(IC1_); if(!GWinput("p = ", Stmp1_, _LBUFF_)) break; sscanf(Stmp1_, "%lg", &p); sprintf(Stmp1_, "p = %f", p); GWsetogn(0, -IC1_); GWputtxt(L*1.1f, L*1.1f, Stmp1_); for(y = 1; y <= L; ++y) { for(x = 1; x <= L; ++x) { if(r[x][y] < p) { GWsrect((float)(x-1), (float)(y-1), (float)x, (float)y, RED); s[x][y] = 1; } else s[x][y] = 0; } } GWflush(-IC1_); // 前の p の値を消す block(IC2_, L/b, s, s1); block(IC3_, L/(b*b), s1, s2); block(IC4_, L/(b*b*b), s2, s3); GWsetogn(0, 1); } } void block(int IC9_, int Ln, double w[][33], double wr[][33]) { int x, xc, y, yc; GWselvp(IC9_); GWsetogn(0, -IC9_); for(y = 1; y <= Ln; ++y) { yc = 2*y - 1; for(x = 1; x <= Ln; ++x) { xc = 2*x - 1; // セルが縦方向につながている -> 繰り込まれた格子点が占有される if(w[xc][yc]*w[xc][yc + 1]==1 || w[xc + 1][yc]*w[xc + 1][yc + 1]==1) { wr[x][y] = 1; GWsrect((float)(x-1), (float)(y-1), (float)x, (float)y, RED); } else wr[x][y] = 0; } } GWflush(-IC9_); }