next up previous contents
Next: Main menu in Objective Up: geom Previous: Sphere Lattices   Contents

Main menu in Turbo C

Unless one wants to use the windowing facilities of a language like TURBO C, the interaction of the program with the user consists mostly of placing informative messages and data at various places on the screen, and in reading the keyboard.

To a certain extent mouse movements can be incorporated along with keystrokes, especially to enhance the use of arrows to move the cursor. As extensions of the alphabet, both the function keys and the editing keys can be placed in the menu, all with the intention of confining commands to single letter sequences.

So far, GEOM has not made as extensive use of these opportunities as some other programs have done.

main() {
char   k;
int    i, j;

    videomode(COLGRAF);
    videoclear();
    videopalette(REDYEGR);
    videocursor(0,2,0);


k=' ';
di=9; dj=1;                        /* demonstration menu (dj=1 or DCOLS) */
pi=6; pj=7;                        /* parameter menu                     */
si=0; sj=1;                        /* screen format menu                 */
dmii=10;                           /* active demonstration               */
bg=17;
smen[0]=0; slim[0]=3;                /* x-y, y-z, or x-r main graph      */
smen[1]=0; slim[1]=2;                /* parabolic/cartesian coordinates  */
r0[0]=r0[1]=r0[2]=0.0;
a0[0]=a0[1]=a0[2]=45.0;
b0[0]=b0[1]=b0[2]=30.0;

pitc=86.0;
leng=2500.0;
videobackground(bg);

radhy=0.50; radca=0.75; radsu=1.00; radfe=1.45;

tu[0]=3; for (i=1; i<5; i++) tu[i]=1;  tu[5]=2;

for (i=0; i<6; i++) abe[i]=1; for (i=6; i<12; i++) abe[i]=2;

for (i=0; i<5; i++) afc[i]=2; for (i=5; i<10; i++) afc[i]=1; afc[10]=3;
for (i=11; i<16; i++) afc[i]=1; for (i=16; i<21; i++) afc[i]=2;

    geoat(s,-0.8, 0.0, 0.3, 1.6, 30.0, 40.0, 59.0, 0);
    geoat(s, 0.6, 0.2,-0.2, 1.0,-30.0,-95.0,-22.0, 1);

    geoat(t,-0.8, 0.0, 0.3, 1.6, 30.0, 40.0, 59.0, 0);
    geoat(t, 0.6,-0.8,-0.2, 0.7,-30.0,-95.0,-22.0, 1);
    geoat(t, 0.9, 0.5, 0.0, 1.6, 40.0,-75.0,-62.0, 0);

    geoat(u, 0.0, 1.8, 0.0, 1.25, -45.0, 45.0, 45.0, 0);
    geoat(u, 1.7, 0.0, 1.4, 0.47,  30.0, 50.0, 40.0, 1);
    geoat(u, 0.8, 0.0, 0.9, 0.47,  30.0, 50.0,-40.0, 2);
    geoat(u,-0.3, 0.0,-0.2, 0.47,  30.0, 50.0, 40.0, 3);
    geoat(u,-0.9, 0.0,-1.1, 0.47,  30.0, 50.0, 40.0, 4);
    geoat(u,-1.3, 0.2, 0.8, 0.36,  30.0, 50.0, 40.0, 5);

    molbe(be,radca,1.2*radca,radhy,1.8*radca);

    molsu(su,radsu); geosp(su,0.67,8);

    molfc(fc,radfe,radca,radhy);

for (i=0; i<12; i++) for (j=0; j<12; j++) bbe[i][j]=0;
for (i=0; i<6; i++) bbe[i][(i+1)%6]=1;
for (i=0; i<6; i++) bbe[i][i+6]=1;

while (1!=0) {
  videocursor(0,0,0); printf(" -GEOM-");
  tidat();
  di=dmii-1;
  pi=pj-1;
  spheu(uu,b0);
  videocursor(0,2,0); printf("? %1c",k);
   while (!kbdst()) videocursor(0,2,0);
   k=kbdin();
   if (k=='q') {videomode(T80X25); return;};
  videocursor(0,2,0); printf(" %1c ",k);
   switch (k) {

  /* demonstration menu with typical parameters and initial conditions */

  case '\273': case '#':                        /* F1 key */
    dmii=dmenu();
    videomode(COLGRAF);
    videopalette(REDYEGR);
    break;

  /* parameter and initial condition menu activated for +,- */

  case '\274': case '$':                        /* F2 key */
    pj=pmenu();    
    videomode(COLGRAF);
    videopalette(REDYEGR);
    break;

  /* */

  case '\275': case '%':                        /* F3 key */
    sj=smenu();
    videomode(COLGRAF);
    videopalette(REDYEGR);                        /* white/cyan/magenta */
    break;

  case '\322':                                        /* INSERT key */
    geopi(dmii);
    break;

  case '\323':                                        /* DELETE key */
    geopi(0);
    break;

  case '\307':                                        /* PAR UP key */
    pj--;
    if (pj==0) pj=PROWS;
    geoqi(pj);
    break;

  case '\317':                                        /* PAR DOWN key */
    if (pj>=PROWS) pj=0;
    pj++;
    geoqi(pj);
    break;

  case '\311':                                        /* PAGE UP key */
    dmii--;
    if (dmii==0) dmii=DROWS;
    geopi(dmii);
    break;

  case '\321':                                        /* PAGE DOWN key */
    if (dmii==DROWS) dmii=0;
    dmii++;
    geopi(dmii);
    break;

case 'a':                                        /* show skeleton */
    geoni(dmii);
    break;

case 'b':                                        /* draw bonds         */
    geobo(dmii);
    break;

case 'c':
    eomsf(t,3);
    geosp(t,0.5,3);
    eomsf(t,3);
    geosr(t,2.0,3);
    break;

case 'd':
/*    eomsf(be,12); */
    break;

/* echo character from keyboard */

case 'e': 
    videocursor(0,0,35);
    printf("%1o",kbdin());
    break;

/* intersecting spheres */

case 'f':
    geosi(s);
    break;

case 'g':                                        /* draw molecule */
    geodi(dmii);
    break;

case 'h':
    geosg(r0,1.5,a0,14,8);
    break;

case 'i':
    geosl(r0,1.25,a0,14,17);
    break;

case 'j': geori(45.0,1.0,1.0,1.0,dmii); break;

case 'k': geori(60.0,1.0,1.0,1.0,dmii); break;

case 'l': geori(90.0,0.2,0.5,1.0,dmii); break;

case 'm': geori(90.0,1.0,0.3,0.2,dmii); break;

case 'n': geori(90.0,0.4,1.0,0.2,dmii); break;

/* read center of sphere */

case 'o':
    twopc('o');
    scanf("%F %F %F",&r0[0],&r0[1],&r0[2]);
    break;

/* read parameters */

case 'p':
    geoqi(pj);
/*    scanf("%F %F %F %F",&g1,&g2,&z1,&z2); */
    break;

/* read euler angles a0 */

case 'u':
    twopc('u');
    scanf("%F %F %F",&a0[0],&a0[1],&a0[2]);
    break;

/* read euler angles b0 */

case 'v':
    twopc('v');
    scanf("%F %F %F",&b0[0],&b0[1],&b0[2]);
    break;

/* set up background */

case 'w': videobackground(bg); break;

/* clear the screen */

case 'z':
    twopc('z');
    videomode(COLGRAF);
    videoclear();
    videopalette(REDYEGR);
    videobackground(bg);
    videocursor(0,2,0);
    break;

/* increase parameter */

case '+':
  switch (pj) {
    case 1: bg++; if (bg==32) bg=0; break;
    case 2: pitc*=1.125; break;
    case 3: leng*=1.414; break;
    case 4: radhy*=1.414; molfc(fc,radfe,radca,radhy); break;
    case 5: radca*=1.414; molfc(fc,radfe,radca,radhy); break;
    case 6: radsu*=1.250; molsu(su,radsu); geosp(su,0.67,8); break;
    case 7: radfe*=1.250; molfc(fc,radfe,radca,radhy); break;
    default: break;
      }
    geoqi(pj);
    break;

/* decrease parameter */

case '-':
  switch (pj) {
    case 1: if (bg==0) bg=32; bg--; break;
    case 2: pitc*=1.125; break;
    case 3: leng/=1.414; break;
    case 4: radhy/=1.414; molfc(fc,radfe,radca,radhy); break;
    case 5: radca/=1.414; molfc(fc,radfe,radca,radhy); break;
    case 6: radsu/=1.250; molsu(su,radsu); geosp(su,0.67,8); break;
    case 7: radfe/=1.250; molfc(fc,radfe,radca,radhy); break;
    default: break;
      }
    geoqi(pj);
    break;

/* go to next parameter with down arrow */

case '\320':
  twocur(pj); printf("=");
  if (pi==PROWS-1) pi=0; else pi++;
  pj=pi+1;
  break;

/* go to previous parameter with up arrow */

case '\310':
  twocur(pj); printf("=");
  if (pi==0) pi=PROWS-1; else pi--;
  pj=pi+1;
  break;

/* ? --- menu listing */

  case '?':
    twopc('?');
    videomode(COLGRAF);
    videopalette(REDYEGR);
    videocursor(0,9,0);
    printf(" F1 - demonstrations\n");
    printf(" F2 - parameters\n");
    printf(" ins - show demo\n");
    printf(" del - clear demo\n");
    printf(" pg up,dn change demo\n");
    printf(" q - quit\n");
    printf(" z - clear screen\n");
    printf(" ? - show menu\n");
    break;

  default: break;
  }  /* end switch */
}    /* end while  */

}  /* end main */



Pedro Hernandez 2004-05-13