home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #2 / amigaacscoverdisc1998-021998.iso / utilities / shareware / dev / libx11 / graphics_examples / class3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-31  |  16.3 KB  |  886 lines

  1. /* Program 3 -- Draw four graphs 
  2.    Bert Nelson                  
  3.    Copyright 1992 Bert Nelson
  4.  
  5.    Graph One   -- Line Graphs 
  6.    Graph Two   -- bar graphs     
  7.    Graph Three -- pie chart      
  8.    Graph Four  -- sin/cos        
  9.  
  10.    Instructions:
  11.    Press the key '1' to see Graph One
  12.    Press the key '2' to see Graph Two
  13.    Press the key '3' to see Graph Three
  14.    Press the key '4' to see Graph Four
  15.  
  16.    Press the letter 'q' to quit the program
  17.  
  18.  
  19.    Permission to use, copy, modify, and distribute this software and its
  20.    documentation for any purpose and without fee is hereby granted,
  21.    provided that the above copyright notice appear in all copies and that
  22.    both that copyright notice and this permission notice appear in
  23.    supporting documentation.  It is provided "as is" without any express or
  24.    implied warranty.
  25.  
  26.    Bert Nelson DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  27.    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  28.    Bert Nelson BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  29.    ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  30.    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  31.    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  32.    SOFTWARE.
  33.  
  34.  
  35. */
  36.  
  37.  
  38. #include <X11/Xlib.h>
  39. #include <X11/Xutil.h>
  40. #include <math.h>
  41.  
  42.  
  43. /* set up defines */
  44.  
  45.  
  46. #define PI 3.141592654
  47.  
  48. char name[] = "Program Three - by Bert Nelson";
  49. Font font;
  50. static char *ncolors[9] = { 
  51.     " ", "blue","red","green4",
  52.     "magenta1","brown","chocolate",
  53.     "gold1","DarkOrchid4"};
  54.  
  55. unsigned long fore,back;
  56.  
  57. Colormap color_map;
  58. XColor colors[8];
  59. XColor exact_colors[8];
  60.  
  61.  
  62.  
  63. main(argc,argv)
  64. int argc;
  65. char **argv;
  66. {
  67.     Display *mydisplay;
  68.     Window  mywindow,child1,child2,child3,child4;
  69.     GC mygc;
  70.     XEvent myevent;
  71.     KeySym mykey;
  72.     XSizeHints myhint;
  73.  
  74.     int myscreen;
  75.     unsigned long myforeground, mybackground;
  76.     int i;
  77.     char text[10];
  78.     int done;
  79.  
  80.     /* open up a display and get the default screen */
  81.  
  82.  
  83.     mydisplay = XOpenDisplay("");
  84.  
  85.     myscreen = DefaultScreen (mydisplay);
  86.  
  87.  
  88.     /* extract black and white colors from color map */
  89.  
  90.     back = mybackground = WhitePixel (mydisplay, myscreen);
  91.     fore = myforeground = BlackPixel (mydisplay, myscreen);
  92.  
  93.  
  94.     /* set up attributes for the window */
  95.  
  96.     myhint.x = 0;
  97.     myhint.y = 0;
  98.     myhint.width =  1005;
  99.     myhint.height = 705;
  100.     myhint.flags = PPosition | PSize;
  101.  
  102.     /* create a basic generic window with the above attributes */
  103.  
  104.  
  105.     mywindow = XCreateSimpleWindow (mydisplay,
  106.         DefaultRootWindow (mydisplay),
  107.         myhint.x, myhint.y, myhint.width, myhint.height,
  108.         2, myforeground, mybackground);
  109.  
  110.     child1 = XCreateSimpleWindow (mydisplay,
  111.             mywindow,
  112.             0, 0, 500, 350,
  113.             2, myforeground, mybackground);
  114.  
  115.         child2 = XCreateSimpleWindow (mydisplay,
  116.             mywindow,
  117.             500, 0, 498, 350, 
  118.             2, myforeground, mybackground);
  119.  
  120.         child3 = XCreateSimpleWindow (mydisplay,
  121.             mywindow,
  122.             0, 350, 500, 350,
  123.             2, myforeground, mybackground);
  124.  
  125.         child4 = XCreateSimpleWindow (mydisplay,
  126.             mywindow,
  127.             500, 350, 498, 350,
  128.             2, myforeground, mybackground);
  129.  
  130.     
  131.  
  132.     /* Set up the title of the window and set up   
  133.        background and foreground colors */
  134.  
  135.  
  136.     XSetStandardProperties (mydisplay, mywindow, name, name,
  137.         None, argv, argc, &myhint);
  138.  
  139.     mygc = XCreateGC (mydisplay, mywindow, 0, 0);
  140.  
  141.  
  142.     XSetBackground (mydisplay, mygc, mybackground);
  143.     XSetForeground (mydisplay, mygc, myforeground);
  144.  
  145.  
  146.     /* ask for input from the keyboard */
  147.  
  148.     XSelectInput (mydisplay, mywindow,
  149.         ButtonPressMask | KeyPressMask | ExposureMask);
  150.  
  151.  
  152.     /* Map the window the the screen */
  153.  
  154.  
  155.     XMapRaised (mydisplay, mywindow);
  156.  
  157.     XMapRaised  (mydisplay,child1);
  158.  
  159.         XMapRaised  (mydisplay,child2);
  160.         XMapRaised  (mydisplay,child3);
  161.         XMapRaised  (mydisplay,child4);
  162.  
  163.  
  164.  
  165.     /* set up named colors, so they can be easily used */
  166.  
  167.     color_set_up(mydisplay);
  168.  
  169.     /* This loop drives the program */
  170.  
  171.  
  172.     done = 0;
  173.  
  174.  
  175.     while (done == 0)
  176.     {
  177.         XNextEvent (mydisplay, &myevent );
  178.         switch (myevent.type)
  179.  
  180.         {
  181.  
  182.         case Expose:
  183.             if (myevent.xexpose.count == 0)
  184.                 break;
  185.  
  186.         case MappingNotify:
  187.             XRefreshKeyboardMapping (&myevent);
  188.             break;
  189.  
  190.             /* if a key is pressed then branch to the
  191.                        corresponding subroutine */
  192.  
  193.         case KeyPress:
  194.         case ButtonPress:
  195.  
  196.             i = XLookupString (&myevent, text, 10, &mykey, 0);
  197.  
  198.             if (i == 1)
  199.             {
  200.                 switch(text[0])
  201.                 {
  202.                 case '1' :
  203.                     line_graph(mydisplay,child1,mygc);
  204.                     break;
  205.  
  206.                 case '2' :
  207.                     bar_graph(mydisplay,child2,mygc);
  208.                     break;
  209.  
  210.  
  211.                 case '3' :
  212.  
  213.                     pie_graph(mydisplay,child3,mygc);
  214.                     break;
  215.  
  216.                 case '4' :
  217.  
  218.                     sin_cos(mydisplay,child4,mygc);
  219.                     break;
  220.  
  221.                 case 'q' :
  222.  
  223.                     done = 1;
  224.                     break;
  225.  
  226.  
  227.  
  228.  
  229.                 } /* switch text */
  230.  
  231.  
  232.  
  233.             }  /* if i */
  234.  
  235.  
  236.         } /* switch */
  237.  
  238.  
  239.     } /* while (done == 0) */
  240.  
  241.     /* Free up all the resources and shutdown gracefully */
  242.  
  243.     XFreeGC (mydisplay, mygc);
  244.     XDestroyWindow (mydisplay, mywindow);
  245.     XCloseDisplay (mydisplay);
  246.  
  247.     exit(0);
  248.  
  249. } /* end main */
  250.  
  251.  
  252.  
  253. /* Draw a line graph */
  254.  
  255.  
  256. line_graph(the_display,the_window,the_gc)
  257.  
  258. Display *the_display;
  259. Window the_window;
  260. GC the_gc;
  261.  
  262. {
  263.  
  264.     XPoint male_line[5];
  265.     XPoint female_line[5];
  266.     XPoint total_line[5];
  267.  
  268.  
  269.     total_line[0].x = 110;
  270.     total_line[0].y = 229;
  271.     total_line[1].x = 184;
  272.     total_line[1].y = 198;
  273.     total_line[2].x = 257;
  274.     total_line[2].y = 166;
  275.     total_line[3].x = 330;
  276.     total_line[3].y = 96;
  277.     total_line[4].x = 396;
  278.     total_line[4].y = 25;
  279.  
  280.     male_line[0].x = 110;
  281.     male_line[0].y = 253;
  282.     male_line[1].x = 184;
  283.     male_line[1].y = 237;
  284.     male_line[2].x = 257;
  285.     male_line[2].y = 214;
  286.     male_line[3].x = 330;
  287.     male_line[3].y = 206;
  288.     male_line[4].x = 396;
  289.     male_line[4].y = 182;
  290.  
  291.  
  292.     female_line[0].x = 110;
  293.     female_line[0].y = 278;
  294.     female_line[1].x = 184;
  295.     female_line[1].y = 261;
  296.     female_line[2].x = 257;
  297.     female_line[2].y = 214;
  298.     female_line[3].x = 330;
  299.     female_line[3].y = 164;
  300.     female_line[4].x = 396;
  301.     female_line[4].y = 148;
  302.  
  303.     /* Draw X and Y axis */
  304.  
  305.     XDrawLine(the_display,the_window,the_gc,45,20,45,326);
  306.  
  307.     XDrawLine(the_display,the_window,the_gc,20,300,420,300);
  308.  
  309.     XDrawLine(the_display,the_window,the_gc,41,25,49,25);
  310.  
  311.     /* Draw lines through the x axis */
  312.  
  313.     XDrawLine(the_display,the_window,the_gc,110,295,110,305);
  314.  
  315.     XDrawLine(the_display,the_window,the_gc,184,295,184,305);
  316.  
  317.     XDrawLine(the_display,the_window,the_gc,257,295,257,305);
  318.  
  319.     XDrawLine(the_display,the_window,the_gc,330,295,330,305);
  320.  
  321.     XDrawLine(the_display,the_window,the_gc,396,295,396,305);
  322.  
  323.  
  324.     /* Change color for the line */
  325.  
  326.     XSetForeground(the_display,the_gc,colors[8].pixel);
  327.  
  328.  
  329.     /* Draw the total line */
  330.  
  331.     XSetLineAttributes(the_display,the_gc,1,LineSolid,
  332.         CapRound,JoinRound);
  333.  
  334.     XDrawLine(the_display,the_window,the_gc,60,75,90,75);
  335.  
  336.     XDrawImageString(the_display,the_window,the_gc,95,75,
  337.         "Total",strlen("Total"));
  338.  
  339.     XDrawLines(the_display,the_window,the_gc,total_line,5,
  340.         CoordModeOrigin);
  341.  
  342.  
  343.  
  344.     /* Change the color */
  345.  
  346.     XSetForeground(the_display,the_gc,colors[2].pixel);
  347.  
  348.     /* Draw the male line */
  349.  
  350.     XSetLineAttributes(the_display,the_gc,LineOnOffDash,
  351.         CapRound,JoinRound);
  352.  
  353.     XDrawLine(the_display,the_window,the_gc,60,35,90,35);
  354.  
  355.     XDrawImageString(the_display,the_window,the_gc,95,35,
  356.         "Male",strlen("Male"));
  357.  
  358.     XDrawLines(the_display,the_window,the_gc,male_line,5,
  359.         CoordModeOrigin);
  360.  
  361.  
  362.  
  363.  
  364.     /* Change the color */
  365.  
  366.     XSetForeground(the_display,the_gc,colors[1].pixel);
  367.  
  368.     /* Draw the female line */
  369.  
  370.     XSetLineAttributes(the_display,the_gc,LineDoubleDash,
  371.         CapRound,JoinRound);
  372.  
  373.     XDrawLine(the_display,the_window,the_gc,60,55,90,55);
  374.  
  375.     XDrawImageString(the_display,the_window,the_gc,95,55,
  376.         "Female",strlen("Female"));
  377.  
  378.     XDrawLines(the_display,the_window,the_gc,female_line,5,
  379.         CoordModeOrigin);
  380.  
  381.     reset_colors(the_display,the_gc);
  382.  
  383.  
  384.  
  385.     /* Draw graph title, source and numbers */
  386.  
  387.     XDrawImageString(the_display,the_window,the_gc,
  388.         11,28,"4730",strlen("4730"));
  389.  
  390.     XDrawImageString(the_display,the_window,the_gc,
  391.         60,15,"Two Year College Enrollments (in thousands)",
  392.         strlen("Two Year College Enrollments (in thousands)"));
  393.  
  394.  
  395.     XDrawImageString(the_display,the_window,the_gc,
  396.         11,345,"Source: Statistical Abstract of the United States",
  397.         strlen("Source: Statistical Abstract of the United States"));
  398.  
  399.     XDrawImageString(the_display,the_window,the_gc,
  400.         105,320,"65 ",3);
  401.  
  402.     XDrawImageString(the_display,the_window,the_gc,
  403.         179,320,"70 ",3);
  404.  
  405.     XDrawImageString(the_display,the_window,the_gc,
  406.         252,320,"75 ",3);
  407.  
  408.     XDrawImageString(the_display,the_window,the_gc,
  409.         325,320,"80 ",3);
  410.  
  411.     XDrawImageString(the_display,the_window,the_gc,
  412.         391,320,"85 ",3);
  413.  
  414.  
  415.     XSetLineAttributes(the_display,the_gc,1,LineSolid,
  416.         CapRound,JoinRound);
  417.  
  418.  
  419. }
  420.  
  421.  
  422. /* draw the pie graph with a legend */
  423.  
  424.  
  425. pie_graph(the_display,the_window,the_gc)
  426.  
  427. Display *the_display;
  428. Drawable the_window;
  429. GC the_gc;
  430.  
  431. {
  432.  
  433.     int i;
  434.     int index=0;
  435.     int degrees[13];
  436.  
  437.     degrees[0] = 0;
  438.     degrees[1] = 25;
  439.     degrees[2] = 25;
  440.     degrees[3] = 65;
  441.     degrees[4] = 65;
  442.     degrees[4] = 120;
  443.     degrees[5] = 120;
  444.     degrees[6] = 192;
  445.     degrees[7] = 192;
  446.     degrees[8] = 360;
  447.     degrees[9] = 0;
  448.  
  449.  
  450.     for( i=0; i<9; i++)
  451.  
  452.     {
  453.  
  454.  
  455.  
  456.         if (degrees[i] != degrees[i+1] )
  457.  
  458.         {
  459.             index++;
  460.  
  461.             if (index == 6)
  462.                 break;
  463.  
  464.             XSetForeground(the_display,the_gc,colors[index].pixel);
  465.  
  466.             XFillArc(the_display,the_window,the_gc,
  467.                     75,50,200,200,degrees[i] * 64, 
  468.                 (degrees[i+1] - degrees[i])*64);
  469.  
  470.             display_legend(the_display,the_window,the_gc,index);
  471.  
  472.         } /* end if */
  473.  
  474.  
  475.  
  476.  
  477.     } /* end for loop */
  478.  
  479.     reset_colors(the_display,the_gc);
  480.  
  481.     /* Display title and credit */
  482.  
  483.  
  484.  
  485.     XDrawImageString(the_display,the_window,the_gc,
  486.             50,30,
  487.         "Computer Use Among Elementary and Secondary School Students",
  488.         59);
  489.  
  490.     XDrawImageString(the_display,the_window,the_gc,
  491.             40,315,
  492.             "Source: The Second National U.S. School Uses of Microcomputers Survey",69);
  493.  
  494.  
  495. }
  496.  
  497.  
  498.  
  499.  
  500.  
  501. /* display the legend for the pie chart one at time */
  502.  
  503. display_legend(the_display,the_window,the_gc,idx)
  504.  
  505. Display *the_display;
  506. Window the_window;
  507. GC the_gc;
  508. int idx;
  509. {
  510.  
  511.         /* display the legend one line at a time */
  512.   
  513.  
  514.     if (idx == 5)
  515.  
  516.     {
  517.  
  518.  
  519.  
  520.         XFillRectangle(the_display,the_window,the_gc,
  521.             325,120,13,13);
  522.  
  523.         reset_colors(the_display,the_gc);
  524.  
  525.         XDrawImageString(the_display,the_window,the_gc,
  526.             168,185,"47%",3);
  527.  
  528.  
  529.         XDrawImageString(the_display,the_window,the_gc,
  530.             345,130,"Instruction",11);
  531.  
  532.     }
  533.  
  534.  
  535.     if (idx == 4)
  536.  
  537.  
  538.     {
  539.         XFillRectangle(the_display,the_window,the_gc,
  540.             325,140,13,13);
  541.  
  542.         reset_colors(the_display,the_gc);
  543.  
  544.         XDrawImageString(the_display,the_window,the_gc,
  545.             100,120,"20%",3);
  546.  
  547.         XDrawImageString(the_display,the_window,the_gc,
  548.             345,150,"Programming",11);
  549.     }
  550.  
  551.  
  552.  
  553.     if (idx == 3)
  554.  
  555.     {
  556.  
  557.         XFillRectangle(the_display,the_window,the_gc,
  558.             325,160,13,13);
  559.  
  560.         reset_colors(the_display,the_gc);
  561.  
  562.         XDrawImageString(the_display,the_window,the_gc,
  563.             165,75,"15%",3);
  564.  
  565.  
  566.         XDrawImageString(the_display,the_window,the_gc,
  567.             345,170,"Problem Solving",15);
  568.  
  569.     }
  570.  
  571.  
  572.     if (idx == 2)
  573.  
  574.     {
  575.         XFillRectangle(the_display,the_window,the_gc,
  576.             325,180,13,13);
  577.  
  578.         reset_colors(the_display,the_gc);
  579.  
  580.         XDrawImageString(the_display,the_window,the_gc,
  581.             220,95,"11%",3);
  582.  
  583.         XDrawImageString(the_display,the_window,the_gc,
  584.             345,190,"Word Processing",15);
  585.     }
  586.  
  587.  
  588.  
  589.     if (idx == 1)
  590.  
  591.  
  592.     {
  593.         XFillRectangle(the_display,the_window,the_gc,
  594.             325,200,13,13);
  595.  
  596.         reset_colors(the_display,the_gc);
  597.  
  598.         XDrawImageString(the_display,the_window,the_gc,
  599.             240,135,"7%",2);
  600.  
  601.         XDrawImageString(the_display,the_window,the_gc,
  602.             345,210,"Other",5);
  603.  
  604.     }
  605.  
  606.  
  607. }
  608.  
  609.  
  610.  
  611.  
  612. /* get color values of named colors  */
  613.  
  614. color_set_up(the_display)
  615.  
  616. Display *the_display;
  617.  
  618. {
  619.  
  620.     int i;
  621.  
  622.     color_map = DefaultColormap(the_display,0);
  623.  
  624.     /* get the colors from the color map for the colors named */ 
  625.  
  626.     for (i=1; i<9; i++)
  627.     {
  628.  
  629.         XAllocNamedColor(the_display,color_map,ncolors[i],
  630.             &exact_colors[i],&colors[i]);
  631.  
  632.     }
  633.  
  634. }
  635.  
  636.  
  637. /* change foreground color back to black */
  638.  
  639. reset_colors(display,gc)
  640.  
  641. Display *display;
  642. GC gc;
  643.  
  644.  
  645. {
  646.     XSetForeground(display,gc,fore);
  647. }
  648.  
  649.  
  650. /* draw a bar graph of college population based on sex */
  651.  
  652.  
  653. bar_graph(the_display,the_window,the_gc)
  654.  
  655. Display *the_display;
  656. Window the_window;
  657. GC the_gc;
  658.  
  659. {
  660.  
  661.     int xoff;
  662.  
  663.     /* Draw x and y axis */
  664.  
  665.     XDrawLine(the_display,the_window,the_gc,   
  666.         45,20,45,330);
  667.  
  668.     XDrawLine(the_display,the_window,the_gc,
  669.         20,300,480,300);
  670.  
  671.     XDrawLine(the_display,the_window,the_gc,
  672.         41,50,49,50);
  673.  
  674.  
  675.     /* Draw rectangles and alternate the foreground colors */
  676.  
  677.     xoff = 26;
  678.  
  679.     XSetForeground(the_display,the_gc,colors[2].pixel);
  680.  
  681.     XFillRectangle(the_display,the_window,the_gc,
  682.         xoff*3,250,xoff,50);
  683.  
  684.  
  685.     XSetForeground(the_display,the_gc,colors[1].pixel);
  686.  
  687.     XFillRectangle(the_display,the_window,the_gc,
  688.         xoff*4,275,xoff,25);
  689.  
  690.  
  691.     XSetForeground(the_display,the_gc,colors[2].pixel);
  692.  
  693.     XFillRectangle(the_display,the_window,the_gc,
  694.         xoff*6,205,xoff,95);
  695.  
  696.  
  697.     XSetForeground(the_display,the_gc,colors[1].pixel);
  698.  
  699.     XFillRectangle(the_display,the_window,the_gc,
  700.         xoff*7,225,xoff,75);
  701.  
  702.  
  703.     XSetForeground(the_display,the_gc,colors[2].pixel);
  704.  
  705.     XFillRectangle(the_display,the_window,the_gc,
  706.         xoff*9,155,xoff,145);
  707.  
  708.  
  709.     XSetForeground(the_display,the_gc,colors[1].pixel);
  710.  
  711.     XFillRectangle(the_display,the_window,the_gc,
  712.         xoff*10,180,xoff,120);
  713.  
  714.  
  715.     XSetForeground(the_display,the_gc,colors[2].pixel);
  716.  
  717.     XFillRectangle(the_display,the_window,the_gc,
  718.         xoff*12,105,xoff,195);
  719.  
  720.  
  721.     XSetForeground(the_display,the_gc,colors[1].pixel);
  722.  
  723.     XFillRectangle(the_display,the_window,the_gc,
  724.         xoff*13,60,xoff,240);
  725.  
  726.  
  727.     XSetForeground(the_display,the_gc,colors[2].pixel);
  728.  
  729.     XFillRectangle(the_display,the_window,the_gc,
  730.         xoff*15,75,xoff,225);
  731.  
  732.  
  733.     XSetForeground(the_display,the_gc,colors[1].pixel);
  734.  
  735.     XFillRectangle(the_display,the_window,the_gc,
  736.         xoff*16,50,xoff,250);
  737.  
  738.  
  739.     /* draw legend */
  740.  
  741.     XSetForeground(the_display,the_gc,colors[2].pixel);
  742.  
  743.     XFillRectangle(the_display,the_window,the_gc,
  744.         xoff*3,30,xoff+5,10);
  745.  
  746.  
  747.     XSetForeground(the_display,the_gc,colors[1].pixel);
  748.  
  749.     XFillRectangle(the_display,the_window,the_gc,
  750.         xoff*3,50,xoff+5,10);
  751.  
  752.  
  753.     reset_colors(the_display,the_gc);
  754.  
  755.  
  756.     XDrawImageString(the_display,the_window,the_gc,
  757.         xoff*4+15,37,"Male",4);
  758.  
  759.     XDrawImageString(the_display,the_window,the_gc,
  760.         xoff*4+15,58,"Female",6);
  761.  
  762.  
  763.  
  764.     XDrawImageString(the_display,the_window,the_gc,
  765.         10,58,"2507",4);
  766.  
  767.     XDrawImageString(the_display,the_window,the_gc,
  768.         xoff*2,13,"Two-Year College Enrollments (in thousands)",
  769.         43);
  770.  
  771.  
  772.     /* Display years and source along the bottom */
  773.  
  774.  
  775.     XDrawImageString(the_display,the_window,the_gc,
  776.         xoff-5,345,"Source: Statistical Abstract of the United States",
  777.         49);
  778.  
  779.     XDrawImageString(the_display,the_window,the_gc,
  780.         xoff*4-12,315,"1965",4);
  781.  
  782.     XDrawImageString(the_display,the_window,the_gc,
  783.         xoff*6+13,315,"1970",4);
  784.  
  785.     XDrawImageString(the_display,the_window,the_gc,
  786.         xoff*9+13,315,"1975",4);
  787.  
  788.     XDrawImageString(the_display,the_window,the_gc,
  789.         xoff*12+13,315,"1980",4);
  790.  
  791.     XDrawImageString(the_display,the_window,the_gc,
  792.         xoff*15+14,315,"1985",4);
  793.  
  794.  
  795. }
  796.  
  797. /* draw a sine and cosine wave from -2 PI to +2 PI */
  798.  
  799. sin_cos(the_display,the_window,the_gc)
  800.  
  801. Display *the_display;
  802. Window the_window;
  803. GC the_gc;
  804.  
  805. {
  806.     int idx;
  807.     float i;
  808.     int cosx,cosy,x1,y1;
  809.     float x = 0;
  810.     float tempx;
  811.     float tempy;
  812.     int y = 0;
  813.     int xoff = 254;
  814.     int yoff = 200;
  815.  
  816.  
  817.     /* draw x and y axis */
  818.  
  819.  
  820.     XDrawLine(the_display,the_window,the_gc,80,200,430,200);
  821.  
  822.     XDrawLine(the_display,the_window,the_gc,254,150,254,250);
  823.  
  824.  
  825.     XDrawLine(the_display,the_window,the_gc,102,194,102,206);
  826.  
  827.     XDrawLine(the_display,the_window,the_gc,179,194,179,206);
  828.  
  829.  
  830.     XDrawLine(the_display,the_window,the_gc,330,194,330,206);
  831.  
  832.     XDrawLine(the_display,the_window,the_gc,404,194,404,206);
  833.  
  834.  
  835.     XDrawImageString(the_display,the_window,the_gc,95,215,
  836.         "x axis",6);
  837.  
  838.     XDrawImageString(the_display,the_window,the_gc,260,245,
  839.         "y axis",6);
  840.  
  841.     XDrawImageString(the_display,the_window,the_gc,125,158,
  842.         "sin(x)",6);
  843.  
  844.     XDrawImageString(the_display,the_window,the_gc,153,250,
  845.         "cos(x)",6);
  846.  
  847.     for (i = -2*PI; i<2*PI; i= i + PI/100)
  848.  
  849.     {
  850.  
  851.         /* calculate sine points */
  852.  
  853.         x = i ;
  854.         y = yoff - sin(x) * 35 ;
  855.  
  856.         x1 = x * 24 + xoff;
  857.         y1 =  y;
  858.  
  859.  
  860.         /* calculate cosine points */
  861.  
  862.         tempx = i;
  863.         tempy = yoff - cos(x) * 35 ;
  864.  
  865.         cosx = tempx * 24 + xoff;
  866.         cosy = tempy;
  867.  
  868.         /* plot sine wave */
  869.  
  870.         XSetForeground(the_display,the_gc,colors[1].pixel);
  871.  
  872.         XDrawPoint(the_display,the_window,the_gc,x1,y1);
  873.  
  874.         /* plot cosine wave */
  875.  
  876.         XSetForeground(the_display,the_gc,colors[2].pixel);
  877.  
  878.         XDrawPoint(the_display,the_window,the_gc,cosx,cosy);
  879.  
  880.  
  881.     }
  882.  
  883.     reset_colors(the_display,the_gc);
  884.  
  885. }
  886.