home *** CD-ROM | disk | FTP | other *** search
- /* ROUTINE TO GRAPH REAL POINTS FROM STANDARD INPUT */
- #include <stdio.h>
- #include <exec/types.h>
- #include <graphics/gfxbase.h>
- #include <graphics/display.h>
- #include <graphics/regions.h>
- #include <graphics/gfx.h>
- #include <graphics/gfxmacros.h>
- #include <intuition/intuitionbase.h>
- #include <intuition/intuition.h>
- #include <exec/memory.h>
- #include <hardware/custom.h>
- #include <hardware/dmabits.h>
- #include <libraries/dos.h>
- #include <libraries/diskfont.h>
- #include <devices/audio.h>
- #include <math.h>
-
- float data[5000];
- float xmax;
- int xstart,xstop;
- float xdelta;
- float green = 2.0;
- float blue = 3.0;
- float white = 7.0;
- float black = 0.0;
- float red = 1.0;
- int quitfunction();
- int barchart();
- int barplot = 0;
- int graphchart();
- int graphplot = 1;
- float ymin,ymax;
- float xx,xtic;
- float xwin1,xwin2,ywin1,ywin2;
- char chstr[100];
- int nn;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i;
-
- printf("\n\nIf you are typing in data via standard input\n");
- printf("enter carriage return then CTRL-\\ to end data input.\n\n");
-
- xstart=0;
-
- i=0;
- while( (scanf("%f",&data[i]) ) > 0) i++;
- nn = i;
-
- graph();
- }
- graph()
- {
- int i;
- float x,y;
- int event;
- char keystroke;
- int makegrid;
-
- ymax = -1e10;
- ymin = 1e10;
-
- for(i=0;i<nn;i++) {
- if(data[i]>ymax)ymax=data[i];
- if(data[i]<ymin)ymin=data[i];
- }
-
- ymax = ymax + .05*(ymax-ymin);
- ymin = ymin - .05*(ymax-ymin);
-
- ustart("high2",0.,640.,0.,400.);
- uamenu(1,0,0,"FUNCTION",' ',0,MIDRAWN|MENUENABLED,0);
- uamenu(1,1,0,"GRAPH ",'G',0,MIDRAWN|ITEMTEXT|HIGHCOMP
- |COMMSEQ|ITEMENABLED,graphchart);
-
- uamenu(1,2,0,"BARCHART",'B',0,MIDRAWN|ITEMTEXT|HIGHCOMP
- |COMMSEQ|ITEMENABLED,barchart);
-
- uamenu(1,3,0,"QUIT ",'Q',0,MIDRAWN|ITEMTEXT|HIGHCOMP
- |COMMSEQ|ITEMENABLED,quitfunction);
-
- makegrid = TRUE;
-
- xwin1 = 0.0;
- xwin2 = nn;
- ywin1 = ymin;
- ywin2 = ymax+.05*(ymax-ymin);
-
- uwindo(xwin1,xwin2,ywin1,ywin2);
-
- redraw();
-
- while(TRUE){
- ugrinl(&x,&y,&event,&keystroke);
- upset("colo",white);
-
- sprintf(chstr,"X = %10.3f",x);
- uprint(( xwin1 + .1*(xwin2-xwin1) ),ymax,chstr);
-
- sprintf(chstr,"Y = %10.3f",y);
- uprint(( xwin1 + .4*(xwin2-xwin1) ),ymax,chstr);
- }
- }
-
-
- redraw()
- {
- int i;
- int color;
-
- upset("colo",black);
- uset("fill");
- uoutln();
- uset("nofi");
-
- upset("colo",red);
-
- umove(0.0, ymin);
- udraw((float)nn,ymin);
- udraw((float)nn,ymax);
- udraw(0.0, ymax);
- udraw(0.0, ymin);
-
- umove(0.,data[0]);
-
-
- if(graphplot){
- /* DRAW GRAPH */
- upset("colo",green);
- uwindo(xwin1,xwin2-1.0,ywin1,ywin2);
- for(i=0;i<nn;i++) udraw((float)i,data[i]);
- }
-
- if(barplot){
- /* DRAW BAR CHART */
- uset("rint");
- uwindo(xwin1,xwin2,ywin1,ywin2);
- color = 0;
- for (i=0;i<nn;i++){
- if((color++ % 15) == 0) color = 1;
- upset("colo",(float)color);
- uset("fill");
- urect((float)(i),ymin,(float)i+1,data[i]);
- uset("nofi");
- }
- }
- }
-
- graphchart()
- {
- barplot = 0;
- graphplot = 1;
- redraw();
- }
-
- barchart()
- {
- barplot = 1;
- graphplot = 0;
- redraw();
- }
-
- quitfunction()
- {
- uend();
- exit();
- }
-
-
-