home *** CD-ROM | disk | FTP | other *** search
- /* BAR3D.C */
- #include "stdio.h"
- #include "stdlib.h"
- #include "conio.h"
- #include "string.h"
- #include "eg_proto.h"
-
- extern int main(void );
-
- main()
- {
- sphr_crd rela_obj; /* theta, phi, rho and sd */
- struct vfont * vfontld(); /* vector font to use */
- struct vfont *fk; /* vector font to use */
- stack_cr stackc[3]; /* for the stack bar's color */
- int i,j,barx,bary,basetype,frameflag,bar_bott;
- int barkind=0;
- int fn=0,fn1=1; /* bit map font */
- int bord_color=9; /* border color for the legend */
- int font_color=9; /* font color for the legend */
- int border=0; /* make no border for the legend */
- float barval[12]; /* for cubebar, pyramid and octahdrn */
- /* for the labels */
- char lab0[1][80],lab1[1][80],lab2[3][80],lab3[4][80];
- char lab4[11][20],lab5[11][20];
- char *lab0_p[1],*lab1_p[1],*lab2_p[3],*lab3_p[4],*lab4_p[11],*lab5_p[11];
- char l[3][80]; /* for the legend */
- char *label[3]; /* for the legend */
-
- /* assign the value for real_obj */
- rela_obj.theta=45L; /* rotate 60 along horizontal line */
- rela_obj.phi=45L; /* rotate 60 along vertically line */
- rela_obj.rho=1000L; /* distance between eye and object */
- rela_obj.sd=500L; /* distance between eye and screen */
-
- printf("enter the theta and phi: ");
- scanf("%ld %ld",&rela_obj.theta,&rela_obj.phi);
-
- /* set the ega, mode 16 */
- setvga();
- initgraf(18,0,0);
- clearscr(15);
-
- /* set the world coordinate */
- setview(0,0,639,479);
- setworld(0,0,639,479);
- worldon(1);
-
- /* set the value for 12 bars */
- barx=4; /* there are 4 bars along X-axis */
- bary=3; /* there are 3 bars along Y-axis */
- basetype=0; /* square base type */
- bar_bott=3; /* each bar takes whole unit area */
- frameflag=1; /* only has 2 frames */
-
- /* load the bit map font */
- fontinit();
- if ((font_load(fn,"sbo.sms"))!=0) {
- printf("Wrong from loading sbo.sms\n");
- exit(0);
- }
- if ((font_load(fn1,"roman3.sms"))!=0) {
- printf("Wrong from loading roman3.sms\n");
- exit(-1);
- }
-
- /* load the vector font */
- fk=(struct vfont *)vfontld("K0UR.VEC",&j);
- if(j < 0) {
- printf("\r\nvfontld return:%d\r\n",j);
- exit(-1);
- }
-
- /* using the default colors */
- td_bar_color(-1,-1,-1,-1);
- td_frame_color(15,-1,15);
-
- /* call td_bar_set() to set the attribute of the bar chart */
- td_bar_set(barkind,barx,bary,1,stackc);
-
- /* using the default to set base */
- td_base_dim((float)-1,(float)-1,(float)-1);
- td_graph_dim((float)-1,(float)-1,(float)-1,(float)-1);
- td_base_height(80.0);
-
- /* using the default to set middle plane */
- td_midplane(1,-99,(float)0.0);
-
- /* assign value to label */
- strcpy(lab0[0],"GM CORP.");
- lab0_p[0]=lab0[0];
-
- strcpy(lab1[0],"PRODUCT");
- lab1_p[0]=lab1[0];
-
- strcpy(lab2[0],"1986");
- strcpy(lab2[1],"1987");
- strcpy(lab2[2],"1988");
- for (i=0; i<3; ++i) lab2_p[i]=lab2[i];
-
- strcpy(lab3[0],"JAN-MAR");
- strcpy(lab3[1],"APR-JUN");
- strcpy(lab3[2],"JUL-SEP");
- strcpy(lab3[3],"OCT-DEC");
- for (i=0; i<4; ++i) lab3_p[i]=lab3[i];
-
- strcpy(lab4[0],"-100");
- strcpy(lab4[1],"400");
- for (i=0; i<11; ++i) lab4_p[i]=lab4[i];
-
- strcpy(lab5[0],"-100");
- strcpy(lab5[1],"400");
- for (i=0; i<11; ++i) lab5_p[i]=lab5[i];
-
- td_bar_label(BASE_LEFT,0,lab0_p,fk,1,0);
- td_bar_label(BASE_RIGHT,0,lab1_p,fk,1,0);
- td_bar_label(XY_PLANE_LEFT,2,lab2_p,fk,3,0);
- td_bar_label(XY_PLANE_RIGHT,2,lab3_p,fk,4,0);
- td_bar_label(XZ_PLANE,2,lab4_p,fk,11,1);
- td_bar_label(YZ_PLANE,2,lab5_p,fk,11,1);
-
- /* assign the value to each bar */
- barval[0]=(float)300.0;
- barval[1]=(float)200.0;
- barval[2]=(float)-100.0;
- barval[3]=(float)220.0;
- barval[4]=(float)150.0;
- barval[5]=(float)120.0;
- barval[6]=(float)180.0;
- barval[7]=(float)90.0;
- barval[8]=(float)-80.0;
- barval[9]=(float)80.0;
- barval[10]=(float)190.0;
- barval[11]=(float)100.0;
-
- /* set the value for the legend */
- strcpy(l[0],"FIRST YEAR");
- strcpy(l[1],"SECOND YEAR");
- strcpy(l[2],"THIRD YEAR");
- for (i=0; i<3; ++i) label[i]=l[i];
-
- /* put the title */
- td_title(TOP,"South Mountain Software",0,fn1,fk);
-
- /* put the legend */
- td_legend(3,BOT_CENTER,label,bord_color,font_color,border,fn,fk);
-
- /* call td_chart() to draw the bar chart */
- if ((i=td_chart(400.0,-100.0,basetype,bar_bott,rela_obj,frameflag,barval))!=0)
- printf("error from td_chart %d\n",i);
-
- /* free the font */
- vfontuld(fk);
- fontquit();
-
- /* set back to the text mode */
- getch();
- initgraf(3,0,0);
- return(0);
- }
-