home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 3 / FREEWARE.BIN / towns_os / ok_chem / ok_chem.c < prev    next >
Text File  |  1980-01-02  |  7KB  |  245 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <msdos.cf>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <EGB.h>
  7. #include <MOS.h>
  8. #include <MMI.h>
  9.  
  10. char work[1536];
  11. char para[2048];
  12. char mwork[4096];
  13.  
  14. char gra2[512]={ 0x49,0x49,0x2a,0x00,
  15.                  0x08,0x00,0x00,0x00,
  16.                  0x0f,0x00,
  17.                  0xff,0x00,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  18.                  0x00,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x80,0x02,0x00,0x00,
  19.                  0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0xe0,0x01,0x00,0x00,
  20.                  0x02,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,
  21.                  0x03,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  22.                  0x06,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  23.                  0x0a,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  24.                  0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x02,0x00,0x00,
  25.                  0x12,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  26.                  0x15,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  27.                  0x18,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  28.                  0x19,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
  29.                  0x1a,0x01,0x05,0x00,0x01,0x00,0x00,0x00,0xf0,0x01,0x00,0x00,
  30.                  0x1b,0x01,0x05,0x00,0x01,0x00,0x00,0x00,0xf8,0x01,0x00,0x00,
  31.                  0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  32.                  0x00,0x00,0x00,0x00 };
  33.  /* ↑ TIFF 256色 のヘッダ */
  34.  
  35. char mes[]="O.K_CHEMISTRY_TOOL  v0.1";
  36. char mes2[]="水素原子の波動関数の三次元表示";
  37. char moji[16][11]={"ψ1s","ψ2s","ψ2pz","ψ2px","ψ2py",
  38.                     "ψ3s","ψ3pz","ψ3px","ψ3py",
  39.                     "ψ3dz2","ψ3dxz","ψ3dyz","ψ3dx2-y2","ψ3dxy",
  40.                     "画面セーブ","終了"};
  41. char *gra;
  42. FILE *fp;
  43. double fai,a=1,r,r2,pi=3.1415;
  44. double xx,yy,zz;
  45. double ex,ey,ez,kizami=10,ka=10;
  46. unsigned short x,y,col;
  47. short c,o,ms;
  48. int i,ki;
  49. short miid[16];
  50. short id,mid,cd;
  51. POINT lu,rd;
  52. COLOR wc;
  53. POINT pos;
  54. short sid;
  55. int m1=0,m2,m3;
  56.  
  57. void pset(x,y,col)
  58. unsigned short x,y,col;
  59. {
  60.  EGB_color(work,0,col);
  61.  WORD(para+2)=x;
  62.  WORD(para+4)=y;
  63.  EGB_pset(work,para);
  64. }
  65.  
  66. void main()
  67. {
  68.  gra=(char *)malloc(307712);    /* 画面セーブ用領域確保 */
  69.  if (gra==NULL)
  70.     exit(-1);
  71.  EGB_init(work,1536);
  72.  EGB_resolution(work,0,12);    /* 画面モード12 */
  73.  for (c=0;c<256;c++)
  74.  {
  75.     o=8*c+4;
  76.     DWORD(para+o)=c;
  77.     BYTE(para+o+4)=c;
  78.     BYTE(para+o+5)=c;
  79.     BYTE(para+o+6)=c;
  80.     BYTE(para+o+7)=0;
  81.  }
  82.  DWORD(para+0)=256;
  83.  EGB_palette(work,1,para);    /* パレットをモノクロ256段階に設定 */
  84.  EGB_writePage(work,0);
  85.  EGB_displayPage(work,0,1);
  86.  EGB_color(work,0,255);
  87.  EGB_color(work,1,0);
  88.  EGB_writeMode(work,2);
  89.  EGB_penSize(work,1);
  90.  
  91.  MOS_start(mwork,4096);
  92.  MOS_resolution(0,12);
  93.  MOS_writePage(0);
  94.  MOS_color(0,0xff);
  95.  MOS_horizon(0,639);
  96.  MOS_vertical(0,479);        /* マウス設定(おまじない) */
  97.  
  98.  for (;;)
  99.  {
  100.     MMI_Open(32,2048,work,mwork);    /* MMIライブラリ初期化 */
  101.     MMI_SetPixel(1);
  102.     MMI_FlsEvnt(MSALL,0);
  103.  
  104.     lu.x=120; lu.y=16;
  105.     rd.x=519; rd.y=399;
  106.     wc.frame=0x7f; wc.back=0xff; wc.ch=0;
  107.     id=MMI_EtyWin(&lu,&rd,&wc);    /* ウィンドウ定義 */
  108.  
  109.     lu.x=4;lu.y=8;
  110.     wc.frame=0x7f; wc.back=0xff; wc.ch=0;
  111.     cd=MMI_EtyMsg(id,&lu,mes,&wc);    /* メッセージをウィンドウ上に定義 */
  112.  
  113.     lu.x=24;lu.y=32;
  114.     wc.frame=0x7f; wc.back=0xff; wc.ch=0;
  115.     cd=MMI_EtyMsg(id,&lu,mes2,&wc);
  116.  
  117.     lu.x=0; lu.y=0;
  118.     wc.frame=0x7f; wc.back=0xff; wc.ch=0;
  119.     mid=MMI_EtyMenu(id,&lu,DVERT,FALSE,FALSE,&wc); /* 縦並びメニュー設定 */
  120.  
  121.     for (i=0;i<16;i++)
  122.     {
  123.         miid[i]=MMI_EtyMItem(mid,TRUE,FALSE,0,moji[i]);
  124.                     /* メニューの項目設定 */
  125.     }
  126.  
  127.     MMI_DspWin(id,TRUE,TRUE);    /* 上で定義したウィンドウ表示 */
  128.     lu.x=176; lu.y=64;
  129.     MMI_DspMenu(mid,&lu,TRUE,FALSE);    /* メニュー表示 */
  130.     MOS_disp(1);                /* マウス表示 */
  131.     pos.x=0; pos.y=0; m1=0; ms=0;
  132.     do
  133.     {
  134.         while ((m1&1)!=1)
  135.          MOS_rdpos(&m1,&m2,&m3);
  136.         pos.x=m2; pos.y=m3;         /* マウスのクリックした場所 */
  137.         ms=MMI_MenuSelect(mid,&pos,&sid);/* のメニューの項目のID取得 */
  138.     }
  139.     while ( ENOSLCT==ms );    /* 何もセレクトしていないなら繰り返し*/
  140.  
  141.     ki=0;
  142.     for (i=0;i<16;i++)
  143.      if (miid[i]==ms) ki=i;    /* すなわちkiが選んだ項目の番号 */
  144.  
  145.     MMI_ClsMenu(mid);
  146.     MMI_ClsWin(id);        /* ウィンドウをクリアして下の画面に戻す */
  147.     MOS_disp(0);
  148.  
  149.     if (ki==15) break;
  150.     if (ki!=14)        /* 終了や画面セーブでなければ表示へ移る */
  151.     {
  152.         WORD(para+0)=1;
  153.         for (ez=0;ez<kizami*1.2;ez++)
  154.         {
  155.          zz=(double)(ez/kizami);
  156.          for (ey=0;ey<kizami*1.2;ey++)
  157.          {
  158.           yy=(double)(ey/kizami);
  159.           for (ex=0;ex<kizami*1.2;ex++)
  160.           {
  161.            xx=(double)(ex/kizami);
  162.            r2=(double)((ex*ex+ey*ey+ez*ez)/(kizami*kizami));
  163.            r=sqrt(r2);
  164.            switch (ki)
  165.             {
  166.              case 0:fai=exp(-r);
  167.             break;
  168.              case 1:fai=exp(-r/2)*(2-r)/2;
  169.             break;
  170.              case 2:fai=exp(-r/2)*zz/2;
  171.             break;
  172.              case 3:fai=exp(-r/2)*xx/2;
  173.             break;
  174.              case 4:fai=exp(-r/2)*yy/2;
  175.             break;
  176.              case 5:fai=(27-18*r+2*r*r)*exp(-r/3)/49.73;
  177.             break;
  178.              case 6:fai=(6-r)*exp(-r/3)*zz/4.973;
  179.             break;
  180.              case 7:fai=(6-r)*exp(-r/3)*xx/4.973;
  181.             break;
  182.              case 8:fai=(6-r)*exp(-r/3)*yy/4.973;
  183.             break;
  184.              case 9:fai=exp(-r/3)/1.407*abs(3*zz*zz-r*r);
  185.             break;
  186.              case 10:fai=exp(-r/3)/1.407*xx*zz;
  187.             break;
  188.              case 11:fai=exp(-r/3)/1.407*yy*zz;
  189.             break;
  190.              case 12:fai=exp(-r/3)/0.81216*abs(xx*xx-yy*yy);
  191.             break;
  192.              case 13:fai=exp(-r/3)/0.81216*2*xx*yy;
  193.             break;
  194.              defallt:fai=0.8;
  195.             }
  196.            x=(int)(320-ex*0.866*ka+ey*0.866*ka+ex);
  197.            y=(int)(240-ez*ka+ex/2*ka+ey/2*ka-ez);
  198.            col=(int)(fai*255);
  199.            pset(x,y,col);
  200.           }
  201.          }
  202.         }    /* この上の処理は全く適当 誰かまともにしてください */
  203.     }        /* ここでIFの処理は終わり ずっと下へ飛ぶ */
  204.     else
  205.     {
  206.  
  207.     DWORD(gra2+0x01f0)=0x4b;
  208.     DWORD(gra2+0x01f4)=0x01;
  209.     DWORD(gra2+0x01f8)=0x4b;
  210.     DWORD(gra2+0x01fc)=0x01;
  211.     DWORD(gra2+0)=0x002a4949;
  212.  
  213.     for (i=0;i<512;i++)
  214.     {
  215.         gra[i]=gra2[i];
  216.     }
  217.  
  218.     DWORD(para+0)=(int)gra+512;
  219.     WORD(para+4)=getds();
  220.     WORD(para+6)=0;
  221.     WORD(para+8)=0;
  222.     WORD(para+10)=639;
  223.     WORD(para+12)=479;
  224.  
  225.     EGB_getBlock(work,para);    /* 画面を転送 */
  226.  
  227.     fp=fopen("A:grp.tif","wb");    /* セーブ */
  228.     fwrite(gra,1,307712,fp);
  229.     fclose(fp);
  230.     }
  231.         /* IFの処理が終わったら全てここに来る */
  232.  do
  233.  {
  234.     MOS_rdpos(&m1,&m2,&m3);
  235.  }
  236.  while((m1&1)!=1);    /* 左クリックするまで待つ */
  237.  
  238.  MMI_Close();        /* MMIを終了 */
  239.  }
  240.         /* ここで大きなfor(;;)の無限ループ終了 break文はこの下へ来る */
  241.  free(gra);    /* 領域の開放をお忘れ無く */
  242.  MOS_end();
  243.  exit(0);    /* 一応これを付けておく(いらないかもしれない) */
  244. }
  245.