home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / m / m242 / 3.ddi / DEMOS1.ZIP / BAR3D.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-16  |  4.4 KB  |  161 lines

  1. /* BAR3D.C */
  2. #include "stdio.h"
  3. #include "stdlib.h"
  4. #include "conio.h"
  5. #include "string.h"
  6. #include "eg_proto.h"
  7.  
  8. extern  int main(void );
  9.  
  10. main() 
  11. {
  12.     sphr_crd rela_obj;                 /* theta, phi, rho and sd */
  13.     struct vfont * vfontld();       /* vector font to use */
  14.     struct vfont *fk;                   /* vector font to use */
  15.     stack_cr stackc[3];                 /* for the stack bar's color */
  16.     int i,j,barx,bary,basetype,frameflag,bar_bott;
  17.     int barkind=0;
  18.     int fn=0,fn1=1;                      /* bit map font */    
  19.     int bord_color=9;                    /* border color for the legend */
  20.     int font_color=9;                    /* font color for the legend */
  21.     int border=0;                        /* make no border for the legend */
  22.     float barval[12];                   /* for cubebar, pyramid and octahdrn */
  23.     /* for the labels */
  24.     char lab0[1][80],lab1[1][80],lab2[3][80],lab3[4][80];    
  25.     char lab4[11][20],lab5[11][20];  
  26.     char *lab0_p[1],*lab1_p[1],*lab2_p[3],*lab3_p[4],*lab4_p[11],*lab5_p[11];
  27.     char l[3][80];                        /* for the legend */
  28.     char *label[3];                    /* for the legend */
  29.  
  30.     /* assign the value for real_obj */
  31.     rela_obj.theta=45L;    /* rotate 60 along horizontal line */
  32.     rela_obj.phi=45L;        /* rotate 60 along vertically line */
  33.     rela_obj.rho=1000L;    /* distance between eye and object */
  34.     rela_obj.sd=500L;        /* distance between eye and screen */
  35.  
  36.     printf("enter the theta and phi: ");
  37.     scanf("%ld %ld",&rela_obj.theta,&rela_obj.phi);
  38.  
  39.     /* set the ega, mode 16 */
  40.     setvga();
  41.     initgraf(18,0,0); 
  42.     clearscr(15); 
  43.  
  44.     /* set the world coordinate */
  45.     setview(0,0,639,479); 
  46.     setworld(0,0,639,479);
  47.     worldon(1); 
  48.  
  49.     /* set the value for 12 bars */
  50.     barx=4;                /* there are 4 bars along X-axis */
  51.     bary=3;                /* there are 3 bars along Y-axis */
  52.     basetype=0;            /* square base type */
  53.     bar_bott=3;            /* each bar takes whole unit area */
  54.     frameflag=1;        /* only has 2 frames */
  55.  
  56.     /* load the bit map font */
  57.     fontinit();
  58.     if ((font_load(fn,"sbo.sms"))!=0) {
  59.         printf("Wrong from loading sbo.sms\n");
  60.         exit(0);
  61.         }
  62.     if ((font_load(fn1,"roman3.sms"))!=0) {
  63.         printf("Wrong from loading roman3.sms\n");
  64.         exit(-1);
  65.         }
  66.  
  67.     /* load the vector font */
  68.     fk=(struct vfont *)vfontld("K0UR.VEC",&j); 
  69.     if(j < 0) {
  70.       printf("\r\nvfontld return:%d\r\n",j);
  71.       exit(-1);
  72.       } 
  73.  
  74.     /* using the default colors */
  75.     td_bar_color(-1,-1,-1,-1);
  76.     td_frame_color(15,-1,15);
  77.  
  78.     /* call td_bar_set() to set the attribute of the bar chart */
  79.     td_bar_set(barkind,barx,bary,1,stackc);
  80.  
  81.     /* using the default to set base */
  82.     td_base_dim((float)-1,(float)-1,(float)-1);
  83.     td_graph_dim((float)-1,(float)-1,(float)-1,(float)-1);
  84.     td_base_height(80.0);
  85.  
  86.     /* using the default to set middle plane */
  87.     td_midplane(1,-99,(float)0.0);
  88.  
  89.     /* assign value to label */
  90.     strcpy(lab0[0],"GM CORP.");
  91.     lab0_p[0]=lab0[0];
  92.  
  93.     strcpy(lab1[0],"PRODUCT");
  94.     lab1_p[0]=lab1[0];
  95.  
  96.     strcpy(lab2[0],"1986");
  97.     strcpy(lab2[1],"1987");
  98.     strcpy(lab2[2],"1988");
  99.     for (i=0; i<3; ++i) lab2_p[i]=lab2[i];
  100.  
  101.     strcpy(lab3[0],"JAN-MAR");
  102.     strcpy(lab3[1],"APR-JUN");
  103.     strcpy(lab3[2],"JUL-SEP");
  104.     strcpy(lab3[3],"OCT-DEC");
  105.     for (i=0; i<4; ++i) lab3_p[i]=lab3[i];
  106.  
  107.     strcpy(lab4[0],"-100");
  108.     strcpy(lab4[1],"400");
  109.     for (i=0; i<11; ++i) lab4_p[i]=lab4[i];    
  110.  
  111.     strcpy(lab5[0],"-100");
  112.     strcpy(lab5[1],"400");
  113.     for (i=0; i<11; ++i)    lab5_p[i]=lab5[i];    
  114.  
  115.     td_bar_label(BASE_LEFT,0,lab0_p,fk,1,0);
  116.     td_bar_label(BASE_RIGHT,0,lab1_p,fk,1,0); 
  117.     td_bar_label(XY_PLANE_LEFT,2,lab2_p,fk,3,0);    
  118.     td_bar_label(XY_PLANE_RIGHT,2,lab3_p,fk,4,0); 
  119.     td_bar_label(XZ_PLANE,2,lab4_p,fk,11,1); 
  120.     td_bar_label(YZ_PLANE,2,lab5_p,fk,11,1); 
  121.  
  122.     /* assign the value to each bar */
  123.     barval[0]=(float)300.0;
  124.     barval[1]=(float)200.0;
  125.     barval[2]=(float)-100.0;
  126.     barval[3]=(float)220.0;
  127.     barval[4]=(float)150.0;
  128.     barval[5]=(float)120.0;
  129.     barval[6]=(float)180.0;
  130.     barval[7]=(float)90.0;
  131.     barval[8]=(float)-80.0;
  132.     barval[9]=(float)80.0;
  133.     barval[10]=(float)190.0;
  134.     barval[11]=(float)100.0;
  135.  
  136.     /* set the value for the legend */
  137.     strcpy(l[0],"FIRST YEAR");
  138.     strcpy(l[1],"SECOND YEAR");
  139.     strcpy(l[2],"THIRD YEAR");
  140.     for (i=0; i<3; ++i) label[i]=l[i];
  141.  
  142.     /* put the title */
  143.     td_title(TOP,"South Mountain Software",0,fn1,fk); 
  144.  
  145.     /* put the legend */
  146.     td_legend(3,BOT_CENTER,label,bord_color,font_color,border,fn,fk); 
  147.  
  148.     /* call td_chart() to draw the bar chart */
  149.     if ((i=td_chart(400.0,-100.0,basetype,bar_bott,rela_obj,frameflag,barval))!=0)
  150.         printf("error from td_chart %d\n",i); 
  151.  
  152.     /* free the font */
  153.     vfontuld(fk); 
  154.     fontquit();
  155.  
  156.     /* set back to the text mode */
  157.     getch();
  158.     initgraf(3,0,0);
  159.     return(0);
  160. }
  161.