// PROGRAM iterate_map // ロジスティック写像の反復 #include "TrueBASIC.h" int main(); void initial(double *x0, double *r, char* flag); void set_up_windows(); void map(double *x, double r, char* flag); void change(char* flag); int main() { double r, x; char flag[_LBUFF_]; GWopen(0); set_up_windows(); do { initial(&x, &r, flag); map(&x, r, flag); } while(!(strcmp(flag, "stop") == 0)); GWquit(); return 0; } void initial(double *x0, double *r, char* flag) { char Stmp1_[_LBUFF_]; if(GWinput("growth parameter (0 < r <= 1) = ", Stmp1_, _LBUFF_)) { sscanf(Stmp1_, "%lg", r); (*x0) = 0.3; GWclear(-1); GWrect(0.0f, 0.0f, 1000.0f, 1.0f); sprintf(Stmp1_, "r = %f", (*r)); GWputtxt(10.0f, 0.95f, Stmp1_); strcpy(flag, ""); } else strcpy(flag, "stop"); } void set_up_windows() { double margin, nmax; nmax = 1000; margin = 0.01*nmax; GWindow((float)(-margin), -0.01f, (float)(nmax+margin), 1.01f); } void map(double *x, double r, char* flag) { int iterations; iterations = 0; do { (*x) = 4*r*(*x)*(1 - (*x)); // 写像の反復 iterations = iterations + 1; // 反復回数 printf("%8.6f ", (*x)); // 周期倍化は 2^n 回の反復ごとに改行するとよいことを // 示している.ここで, n = 2 あるいは 3 である. if(((iterations) % 8) == 0) printf("\n"); // 改行 GWsetpxl((float)(iterations % 1000), (float)((*x)), RED); if(TBkeyinput()) { change(flag); } } while(!(strcmp(flag, "stop") == 0 || strcmp(flag, "change") == 0)); printf("\n"); printf("number of iterations = %d\n", iterations); } void change(char* flag) { int k = TBgetkey(); if((k == 'c') || (k == 'C')) strcpy(flag, "change"); else if((k == 's') || (k == 'S')) strcpy(flag, "stop"); }