/* egg roche.c -o roche -Wall */ #include #include #include #define MRATIO_F 0.23 /* 質量比f */ #define XMIN -1.5 /* x座標の範囲 */ #define XMAX 1.5 #define YMIN -1.5 /* y座標の範囲 */ #define YMAX 1.5 #define ZMIN -3.5 /* カラーの範囲 */ #define ZMAX -1.4 #define WINWIDTH 512 /* ウィンドゥのサイズ */ #define WINHEIGHT 512 #define XSAMPLES 30 /* メッシュのサイズ */ #define YSAMPLES 30 #define VXSCALE 0.02 /* 矢印の大きさ */ #define VYSCALE 0.02 #define VCARMAX 0.25 /* 表示する矢印の最大サイズ */ /* #define USE_IMAGEMAGICK */ #define USE_NETPBM float get_fx( float, float, float ) ; float get_fy( float, float, float ) ; float get_phi( float, float, float ) ; int main() { int i,j,key,sl=0,wl=1 ; float f=MRATIO_F ; float x,y,zx,zy,z,ph,ms_w,ms_h ; float zran=(ZMAX-ZMIN) ; float zcen=(ZMAX+ZMIN)/2.0 ; struct color_prms cl = { EGGX_COLOR_BEGIN, /* カラーパターン */ CP_CONTRAST | CP_BRIGHTNESS | CP_GAMMA, /* フラグ */ 1.0, /* コントラスト */ 0.0, /* ブライトネス*/ 1.0, /* γ */ } ; int win ; int cl_r,cl_g,cl_b ; win=gopen(WINWIDTH,WINHEIGHT) ; /* ウィンドゥのタイトル */ window(win,XMIN,YMIN,XMAX,YMAX) ; /* 座標系を変更する */ layer(win,sl,wl) ; puts("【キーボードでの操作方法】") ; puts("'PageUp','PageDown' … 質量比変更") ; puts("'c','C' … カラーパターン") ; puts("'↑','↓','←','→' … カラー調整") ; puts("'[',']' … コントラスト") ; puts("'{','}' … ブライトネス") ; puts("'<','>' … γ補正") ; puts("'s' … 画像を保存") ; puts("'q','Esc' … 終了") ; ms_w=(float)(XMAX-XMIN)/XSAMPLES ; /* メッシュ1個分のサイズ */ ms_h=(float)(YMAX-YMIN)/YSAMPLES ; do{ /* ウィンドゥのタイトル */ winname(win,"ロッシュワールド('s'キーで画像save) f=%g zcen=%g zran=%g", f,zcen,zran) ; for( i=0 ; i'でγ変更 */ cl.gamma += 0.025 ; } else if( key == '>' ){ cl.gamma -= 0.025 ; if( cl.gamma <= 0 ) cl.gamma = 0.025 ; } else if( key == 's' ){ /* 's'キーで保存 */ #ifdef USE_NETPBM saveimg( win,sl,XMIN,YMIN,XMAX,YMAX,"pnmtopng",256, "roche_f=%g.png",f) ; printf("画像を保存: filename='roche_f=%g.png'\n",f) ; #else #ifdef USE_IMAGEMAGICK saveimg( win,sl,XMIN,YMIN,XMAX,YMAX,"convert -compress ZIP",256, "roche_f=%g.eps2",f) ; printf("画像を保存: filename='roche_f=%g.eps2'\n",f) ; #else saveimg( win,sl,XMIN,YMIN,XMAX,YMAX,"",256, "roche_f=%g.ppm",f) ; printf("画像を保存: filename='roche_f=%g.ppm'\n",f) ; #endif #endif } if( f < 0 ) f=0 ; if( zran < 0 ) zran=0.1 ; } while( key != 0x01b && key != 'q' ) ; /* ESCキーか 'q'キーで終了 */ gcloseall() ; return(0) ; } /* テスト粒子に働く力 */ float get_fx( float x, float y, float f ) { float fx0,fx1 ; fx0 = -(x+f/(1+f))/pow(pow(x+f/(1+f),2.0)+y*y,3.0/2.0) ; fx1 = -(x-1/(1+f))*f/pow(pow(x-1/(1+f),2.0)+y*y,3.0/2.0) ; return( fx0+fx1+(1+f)*x ) ; } float get_fy( float x, float y, float f ) { float fy0,fy1 ; fy0= -(y)/pow(pow(x+f/(1+f),2)+y*y,3.0/2.0) ; fy1= -(y)*f/pow(pow(x-1/(1+f),2)+y*y,3.0/2.0) ; return( fy0+fy1+(1+f)*y ) ; } /* ポテンシャル */ float get_phi( float x,float y,float f ) { return( -1/sqrt(pow(x+f/(1+f),2)+y*y) -f/sqrt(pow(x-1/(1+f),2)+y*y) -(1+f)*(x*x+y*y)/2 ) ; }