/* flower.cc */ /* Please compile as following way. gcc -o flower flower.cc -I/usr/X11R6/include -lX11 -L/usr/X11R6/lib -lm or gcc -o flower flower.cc -I/usr/openwin/include -lX11 -L/usr/openwin/lib -lm */ #include #include #include "nxgraph.h" /* == 指定のパラメータでフラワーカオスを描く関数 == */ void Draw_Flower( double a ) { double kx = 8.0*sqrt(2.0+a); double ky = 8.0*sqrt(2.0-a); double x = 1.0, y = 0.0; double nx, ny; int n; /* 65536回連列を辿る */ for( n=1 ; n<65536 ; n++ ){ /* 点を描く */ /* 対称性良く描くために座標に一次変換を施します */ NXDrawPoint( (int)((y+x)*kx)+256, (int)((y-x)*ky)+256 ); /* 次の点を計算する */ nx = a*x + y + 5.0/(1.0+x*x); ny = -x; x = nx; y = ny; } } /* == メイン関数 == */ int main(void) { double a; /* ウィンドウを開く */ NXOpenWindow( "flower chaos", 512, 512 ); /* 描く色を明るいピンク色にする */ NXSetColor( NXGetColor("light pink") ); printf("Flower chaos.\n"); printf("If you input 0, then this program quits.\n\n"); /* aに 0を代入するまで繰り返す */ while(1){ printf("Input a double number from -1.5 to +1.5. :"); scanf("%lf", &a ); if( a==0 ) break; /* 図を描く */ NXClearWindow(); Draw_Flower( a ); } /* ウィンドウを閉じる */ NXCloseWindow(); return(0); }