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

  1.  
  2.  
  3. /*
  4.   Program Six
  5.   Bert Nelson
  6.   Copyright 1992 Bert Nelson
  7.  
  8.   Compile Instructions:  cc file.c -lX11 -lm -o file
  9.  
  10.   Run Instructions:  type 'file' after compiling and click an item
  11.              in the menu bar to do an option 
  12.     
  13.   Program Purpose:  Draw lines, circles, and ellipses using only
  14.             the DrawPoint command.  
  15.  
  16.    Permission to use, copy, modify, and distribute this software and its
  17.    documentation for any purpose and without fee is hereby granted,
  18.    provided that the above copyright notice appear in all copies and that
  19.    both that copyright notice and this permission notice appear in
  20.    supporting documentation.  It is provided "as is" without any express or
  21.    implied warranty.
  22.  
  23.    Bert Nelson DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  24.    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  25.    Bert Nelson BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  26.    ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  27.    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  28.    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  29.    SOFTWARE.
  30.  
  31.  
  32.   */
  33.  
  34. #define ASPECT_RATIO .999 
  35. #define UNDEFINED 0 
  36. #define XOFF 500
  37. #define YOFF 350
  38. #define TRUE 1
  39. #define FALSE 0
  40.  
  41. #include <X11/Xlib.h>
  42. #include <X11/Xutil.h>
  43. #include <string.h>
  44. #include <math.h>
  45. #include <X11/keysym.h>
  46. #define PI 3.141592654    /* set up PI defintion */
  47.  
  48. XPoint points[9];
  49.  
  50.  
  51. /* set strings as global */
  52. int sides;
  53. char enter_str[1];
  54. char rotate_str[1];
  55. char scale_str[1];
  56. char trans_str[1];
  57. char hello[] = "Fundamental Drawing by Bert Nelson";
  58. char lines_str[] = "Line";
  59. char circle_str[] = "Circle";
  60. char view_str[] = "View";
  61. char reset_str[] = "Reset";
  62. char quit_str[] = "Quit";
  63. Font font;
  64. int number;
  65.  
  66. unsigned long black,white;
  67.  
  68. main(argc,argv)
  69. int argc;
  70. char **argv;
  71. {
  72.     Display *mydisplay;
  73.     Window  mywindow,child1,child2,child3,child4;
  74.     GC enter_gc,mygc;
  75.     XEvent myevent;
  76.     KeySym mykey;
  77.     XSizeHints myhint;
  78.     XGCValues gvalues;
  79.     XComposeStatus cs;
  80.     char string[20];
  81.     char newstring[20];
  82.     int nchar;
  83.     int count;
  84.  
  85.     int myscreen;
  86.     unsigned long myforeground, mybackground;
  87.     int i;
  88.     char text[10];
  89.     int done;
  90.  
  91.  
  92.     /* set up display and foreground/background */
  93.  
  94.     mydisplay = XOpenDisplay("");
  95.  
  96.     myscreen = DefaultScreen (mydisplay);
  97.     white = mybackground = WhitePixel (mydisplay, myscreen);
  98.     black = myforeground = BlackPixel (mydisplay, myscreen);
  99.  
  100.     /* create a window with a size of 1000 x 700 */
  101.  
  102.     myhint.x = 0;
  103.     myhint.y = 0;
  104.     myhint.width = 1000;
  105.     myhint.height = 700;
  106.     myhint.flags = PPosition | PSize;
  107.     mywindow = XCreateSimpleWindow (mydisplay,
  108.         DefaultRootWindow (mydisplay),
  109.         myhint.x, myhint.y, myhint.width, myhint.height,
  110.         5, myforeground, mybackground);
  111.  
  112.  
  113.     /* create children windows that will act as menu buttons */
  114.  
  115.     child1 = XCreateSimpleWindow (mydisplay,mywindow,
  116.         0,0,100,25,2,myforeground,mybackground);
  117.  
  118.  
  119.     child2 = XCreateSimpleWindow (mydisplay,mywindow,
  120.         100,0,100,25,2,myforeground,mybackground);
  121.  
  122.  
  123.     child3 = XCreateSimpleWindow (mydisplay,mywindow,
  124.         200,0,100,25,2,myforeground,mybackground);
  125.  
  126.  
  127.     child4 = XCreateSimpleWindow (mydisplay,mywindow,
  128.         300,0,175,25,2,myforeground,mybackground);
  129.  
  130.  
  131.  
  132.     /* print program name at the top */
  133.  
  134.     XSetStandardProperties (mydisplay, mywindow, hello, hello,
  135.         None, argv, argc, &myhint);
  136.  
  137.     /* set up foreground/backgrounds and set up colors */
  138.  
  139.  
  140.     mygc = XCreateGC (mydisplay, mywindow, 0, 0);
  141.  
  142.     gvalues.foreground = myforeground;
  143.     gvalues.background = mybackground;
  144.  
  145.     enter_gc = XCreateGC(mydisplay,child1,0,0);
  146.  
  147.  
  148.     XSetBackground (mydisplay, mygc, mybackground);
  149.     XSetForeground (mydisplay, mygc, myforeground);
  150.     XSetBackground (mydisplay,enter_gc,myforeground);
  151.     XSetForeground (mydisplay,enter_gc,mybackground);
  152.  
  153.  
  154.     /* Load up a font called 8x16 */
  155.  
  156.     font = XLoadFont(mydisplay,"8x16");
  157.     XSetFont(mydisplay,mygc,font);
  158.     XSetFont(mydisplay,enter_gc,font);
  159.  
  160.     /* Ask for input from the mouse and keyboard */
  161.  
  162.     XSelectInput (mydisplay, mywindow,
  163.         ButtonPressMask | KeyPressMask | ExposureMask);
  164.  
  165.     /* map window to the screen */
  166.     XMapRaised (mydisplay, mywindow);
  167.  
  168.     /* Map children windows to the screen */
  169.  
  170.     XMapRaised (mydisplay, child1);
  171.     XMapRaised (mydisplay, child2);
  172.     XMapRaised (mydisplay, child3);
  173.     XMapRaised (mydisplay, child4);
  174.  
  175.     /* Display menu strings */
  176.  
  177.     XNextEvent(mydisplay,&myevent);
  178.  
  179.     XDrawImageString(mydisplay,child1,mygc,
  180.         30,20,lines_str,strlen(lines_str));
  181.  
  182.     XDrawImageString(mydisplay,child2,mygc,
  183.         25,20,circle_str,strlen(circle_str));
  184.  
  185.     XDrawImageString(mydisplay,child3,mygc,
  186.         25,20,reset_str,strlen(reset_str));
  187.  
  188.     XDrawImageString(mydisplay,child4,mygc,
  189.         65,20,quit_str,strlen(quit_str));
  190.  
  191.  
  192.     /* Loop through until a q is press when the cursor is in
  193.            the window, which will cause the application to quit */
  194.  
  195.     done = 0;
  196.     while (done == 0) {
  197.         XNextEvent (mydisplay, &myevent );
  198.  
  199.         if (myevent.type == ButtonPress)
  200.         {
  201.  
  202.             if (myevent.xbutton.subwindow == child1)
  203.             {
  204.                 process_line(mydisplay,mywindow,
  205.                     child1,mygc,enter_gc);
  206.  
  207.             }
  208.  
  209.             if (myevent.xbutton.subwindow == child2)
  210.  
  211.                 process_circle(mydisplay,mywindow,child2,
  212.                     mygc,enter_gc);
  213.  
  214.             if (myevent.xbutton.subwindow == child3)
  215.                 process_reset(mydisplay,mywindow,child3,
  216.                     mygc,enter_gc);
  217.  
  218.  
  219.             if (myevent.xbutton.subwindow == child4)
  220.             {
  221.                 done = 1;
  222.                 break;
  223.             }
  224.  
  225.         }
  226.  
  227.  
  228.         if (myevent.xany.window == mywindow)
  229.         {
  230.             switch (myevent.type) {
  231.  
  232.             case KeyPress:
  233.  
  234.                 {
  235.                     i = XLookupString (&myevent, 
  236.                         text, 10, &mykey, 0);
  237.                     if (i == 1 && text[0] == 'q')
  238.                         done = 1;
  239.                     break;
  240.  
  241.                 } /* case  */
  242.             } /* switch */
  243.  
  244.         } /* end if */
  245.     } /* while */
  246.  
  247.     /* Free up and clean up the windows created */
  248.  
  249.     XFreeGC (mydisplay, mygc);
  250.     XDestroyWindow (mydisplay, mywindow);
  251.     XCloseDisplay (mydisplay);
  252.  
  253.     exit(0);
  254.  
  255.  
  256. }
  257.  
  258. /* Ask for the user to enter the number of sides and the points
  259. for each side.  By definition there are n+1 sides in reality because
  260. you need to draw back to where you started from, so the last point
  261. is assigned to the first point, which makes entering the points
  262. in order important */
  263.  
  264.  
  265. process_line(display,parent,child,parent_gc,child_gc)
  266.  
  267. Display *display;
  268. Window parent,child;
  269. GC parent_gc,child_gc;
  270. {
  271.  
  272.     int i,j,offy,offx;
  273.     Window enter_window;
  274.     XEvent enter_event;
  275.     Font enter_font;
  276.     GC enter_gc;
  277.     int count;
  278.     char text[10];
  279.     int string[10];
  280.     KeySym key;
  281.  
  282.     /* Flash the Enter button on and off */
  283.  
  284.     XClearWindow(display,child);
  285.     XFillRectangle(display,child,parent_gc,0,0,100,25);
  286.     XDrawImageString(display,child,child_gc,
  287.         25,20,lines_str,strlen(lines_str));
  288.     XFlush(display);
  289.     for (i=0; i<1000; i++)
  290.         XNoOp(display);
  291.     XClearWindow(display,child);
  292.     XDrawImageString(display,child,parent_gc,
  293.         25,20,lines_str,strlen(lines_str));
  294.  
  295.  
  296.     /* set up input window */
  297.  
  298.  
  299.     enter_window = XCreateSimpleWindow(display,parent,40,150,
  300.         300,150,3,black,white);
  301.  
  302.     enter_gc = parent_gc;
  303.  
  304.  
  305.     XMapRaised(display,enter_window);
  306.     XClearWindow(display,enter_window);
  307.  
  308.  
  309.     XDrawString(display,enter_window,parent_gc,
  310.         75,25,"Enter Start/End Points",22);
  311.  
  312.     XSelectInput(display,enter_window,ButtonPressMask|KeyPressMask);
  313.  
  314.     /* set up a smaller font */
  315.  
  316.     font = XLoadFont(display,"7x13");
  317.     XSetFont(display,enter_gc,font);
  318.  
  319.     /* reset everything */
  320.  
  321.     XFlush(display);
  322.     string[0] = '\0';
  323.     key = 0;
  324.  
  325.     /* prompt the user to input the number of sides */
  326.  
  327.  
  328.     sides = 2;
  329.  
  330.     /* abort module if there are less than three or greater
  331.                    than eight sides to the figure */
  332.  
  333.  
  334.     /* Clear everything out of the buffers and reset */
  335.  
  336.     XFlush(display);
  337.     string[0] = '\0';
  338.     key = 0;
  339.     text[0] = '\0';
  340.  
  341.  
  342.     /* Ask user to input a x value for n number of sides */
  343.  
  344.     /* Place the input into a string and convert it to
  345.                    a integer */
  346.  
  347.     for (i=0; i<sides; i++)
  348.     {
  349.  
  350.         j = 67;
  351.         XDrawString(display,enter_window,enter_gc,
  352.             15,65+i*30,"Enter x: ",9);
  353.  
  354.         do
  355.         {
  356.             j = j + 8;
  357.             offx = 65+i*30;
  358.             XNextEvent(display,&enter_event);
  359.             count = XLookupString(&enter_event,text,10,&key,0);
  360.             text[count] = '\0';
  361.             if (key != XK_Return)
  362.                 XDrawString(display,enter_window,enter_gc,
  363.                     j,offx,text,1);
  364.             strcat(string,text);
  365.         }        while (key != XK_Return && enter_event.type == KeyPress);
  366.  
  367.         /* convert the input string to an integer */
  368.  
  369.  
  370.         points[i].x = XOFF + strtol(string,NULL,10) ;
  371.  
  372.  
  373.         /* Flush out the buffers and reset everything */
  374.  
  375.  
  376.         XFlush(display);
  377.  
  378.         key = 0;
  379.         string[0] = '\0';
  380.         j = 67;
  381.  
  382.         XDrawString(display,enter_window,enter_gc,
  383.             15,65+i*30+15,"Enter y: ",9);
  384.  
  385.         /* Ask user for a y value for each side of the figure */
  386.         /* Accept a value only after a RETURN key has been pressed */
  387.  
  388.         do
  389.         {
  390.             j = j + 8;      /* move over 8 pixels */
  391.             offy = 80+i*30; /* move down some pixels */
  392.  
  393.             XNextEvent(display,&enter_event); /* ask for input */
  394.  
  395.             count = XLookupString(&enter_event,text,10,&key,0);
  396.             text[count] = '\0';
  397.  
  398.             /* if the return key is NOT pressed display the key
  399.                    that was just pressed */
  400.  
  401.             if (key != XK_Return)
  402.                 XDrawString(display,enter_window,enter_gc,
  403.                     j,offy,text,1);
  404.  
  405.             strcat(string,text);
  406.         }        while (key != XK_Return && enter_event.type == KeyPress);
  407.  
  408.  
  409.         /* flush out buffers and reset */
  410.  
  411.  
  412.         points[i].y =  YOFF - strtol(string,NULL,10);
  413.  
  414.  
  415.         XFlush(display);
  416.         key = 0;
  417.         string[0] = '\0';
  418.  
  419.  
  420.     }
  421.  
  422.  
  423.  
  424.  
  425.     /* Tell the user he must press a key (or a mouse button)
  426.        to exit.  Note:  for this to work the cursor must
  427.            be inside the pop up window */
  428.  
  429.     XDrawString(display,enter_window,enter_gc,
  430.         55,65+i*30+10,"Press any key to Exit",22);
  431.  
  432.     /* Ask for input until a key is pressed */
  433.  
  434.     do
  435.         XNextEvent(display,&enter_event);
  436.     while( enter_event.xbutton.window != enter_window);
  437.  
  438.     /* set the font back to what it was before */
  439.     /* don't ask me why, but it works this way */
  440.  
  441.     font = XLoadFont(display,"8x16");
  442.     XSetFont(display,enter_gc,font);
  443.  
  444.     XDestroyWindow(display,enter_window);
  445.  
  446.  
  447.  
  448.     draw_line(display,parent,parent_gc);
  449.  
  450.  
  451. }
  452.  
  453. /* Draw a line using a simple digital differential analyzer */
  454.  
  455. draw_line(display,parent,gc)
  456.  
  457. Display *display;
  458. Window parent;
  459. GC     gc;
  460.  
  461. {
  462.  
  463.     float xi=0;
  464.     float yi=0;
  465.     float xr=0;
  466.     float yr=0;
  467.     float m;
  468.     float minverse;
  469.     float   xstart = points[0].x;
  470.     float   ystart = points[0].y;
  471.     float   xend = points[1].x;
  472.     float  yend = points[1].y;
  473.     int   temp=0;
  474.     int   temp2=0;
  475.     int   x1=0;
  476.     int   x2=0;
  477.     int   i=0;
  478.  
  479.  
  480.  
  481.  
  482.     XSetBackground(display,gc,white);
  483.     XSetForeground(display,gc,black);
  484.  
  485.     /* Draw x and y axis */
  486.  
  487.     XDrawLine(display,parent,gc,XOFF,0,XOFF,YOFF*2);
  488.     XDrawLine(display,parent,gc,0,YOFF,XOFF*2,YOFF);
  489.  
  490.     /* Draw notches in x and y axis */
  491.  
  492.     for (i=25; i<YOFF*2; i=i+25)
  493.         XDrawLine(display,parent,gc,
  494.             XOFF-3,i,XOFF+3,i);
  495.  
  496.     for (i=25; i<XOFF*2; i= i+25)
  497.         XDrawLine(display,parent,gc,
  498.             i,YOFF-3,i,YOFF+3);
  499.  
  500.  
  501.     XFlush(display);
  502.  
  503.     /* check for a slope of zero -- a vertical line */
  504.  
  505.     if (xend - xstart == 0)
  506.         m = UNDEFINED;
  507.     else
  508.         m = (yend - ystart) / (xend - xstart);
  509.  
  510.  
  511.     if ( (m == UNDEFINED && ystart < yend )
  512.         || (fabs(m) <= 1 && (xstart > xend)) ||
  513.         ((fabs (m) > 1) && (ystart > yend)))
  514.     {
  515.         temp = xend;
  516.         xend = xstart;
  517.         xstart = temp;
  518.         temp = yend;
  519.         yend = ystart;
  520.         ystart = temp;
  521.     }
  522.  
  523.  
  524.     XDrawPoint(display,parent,gc,xstart,ystart);
  525.  
  526.     if (yend == ystart || fabs(m) == 1.0 || (fabs (m) < 1 && m != UNDEFINED))
  527.     {
  528.         yr = ystart;
  529.         for (xi=xstart + 1.0; xi<xend - 1; xi++)
  530.         {
  531.             yr = yr + m;
  532.             temp = xi;
  533.             temp2 = yr + .5;   /* round it off */
  534.             XDrawPoint(display,parent,gc,temp,temp2);
  535.         }
  536.     }
  537.  
  538.     if (fabs (m) > 1 )
  539.     {
  540.         minverse = 1/m;
  541.         xr = xstart;
  542.         for (yi = ystart +1; yi<yend -1; yi++)
  543.         {
  544.             xr = xr + minverse;
  545.             temp =  xr + .5;  /* round it off */
  546.             temp2 =  yi;
  547.             XDrawPoint(display,parent,gc,temp,temp2);
  548.         }
  549.  
  550.     }
  551.  
  552.  
  553.     /* handle vertical lines, which are not done by the DDA */
  554.  
  555.     if ( m == UNDEFINED )
  556.     {
  557.  
  558.         temp = xstart;
  559.         for (yi = yend + 1; yi < ystart -1; yi++)
  560.  
  561.         {
  562.             temp2 = yi;
  563.             XDrawPoint(display,parent,gc,temp,temp2);
  564.         }
  565.  
  566.     }
  567.  
  568.  
  569.     XDrawPoint(display,parent,gc,xend,yend);
  570. }
  571.  
  572.  
  573. /* Ask user to enter in the x and y translation factors for the figure */
  574.  
  575.  
  576.  
  577.  
  578.  
  579. process_circle(display,parent,child,parent_gc,child_gc)
  580.  
  581.  
  582. Display *display;
  583. Window parent,child;
  584. GC parent_gc,child_gc;
  585. {
  586.  
  587.  
  588.     int i,off;
  589.     Window circle_window;
  590.     XEvent circle_event;
  591.     Font circle_font;
  592.     GC circle_gc;
  593.     int count;
  594.     char text[10];
  595.     char radius[10];
  596.     int string[10];
  597.     KeySym key=0;
  598.     float radians;
  599.     double tempcos;
  600.     double tempsin;
  601.     float circle_radius;
  602.  
  603.     int circle_x;
  604.     int circle_y;
  605.  
  606.     /* Flash circle button on and off */
  607.  
  608.     XClearWindow(display,child);
  609.     XFillRectangle(display,child,parent_gc,0,0,100,25);
  610.     XDrawImageString(display,child,child_gc,
  611.         25,20,circle_str,strlen(circle_str));
  612.     XFlush(display);
  613.     for (i=0; i<1000; i++)
  614.         XNoOp(display);
  615.     XClearWindow(display,child);
  616.     XDrawImageString(display,child,parent_gc,
  617.         25,20,circle_str,strlen(circle_str));
  618.  
  619.     /* create a pop up window */
  620.  
  621.     circle_window = XCreateSimpleWindow(display,parent,40,125,
  622.         300,200,3,black,white);
  623.  
  624.     circle_gc = parent_gc;
  625.  
  626.  
  627.     XMapRaised(display,circle_window);
  628.     XClearWindow(display,circle_window);
  629.  
  630.     XDrawString(display,circle_window,parent_gc,
  631.         35,25,"Enter Radius/Center of Circle",30);
  632.  
  633.  
  634.     XSelectInput(display,circle_window,ButtonPressMask
  635.         |KeyPressMask);
  636.  
  637.     /* load up a small font */
  638.  
  639.     font = XLoadFont(display,"7x13");
  640.     XSetFont(display,circle_gc,font);
  641.  
  642.     XDrawString(display,circle_window,circle_gc,
  643.         55,75,"Enter Circle Radius: ",
  644.         22);
  645.     string[0] = '\0';
  646.     key = 0;
  647.     text[0] ='\0';
  648.  
  649.  
  650.     i = 190;
  651.     do
  652.     { 
  653.     i = i + 8;
  654.                 XNextEvent(display,&circle_event);
  655.                 count = XLookupString(&circle_event,text,10,&key,0);
  656.                 text[count] = '\0';
  657.                 if (key != XK_Return)
  658.                         XDrawString(display,circle_window,circle_gc,
  659.                             i,75,text,1);
  660.                 strcat(string,text);
  661.         }        while (key != XK_Return && circle_event.type == KeyPress);
  662.  
  663.  
  664.  
  665.     circle_radius = atof(string);
  666.  
  667.     /* Prompt and get input from the user to the X value to
  668.            circle about */
  669.  
  670.     XDrawString(display,circle_window,circle_gc,
  671.         55,105,"Enter X value of center: ",
  672.         25);
  673.  
  674.  
  675.     /* reset values */
  676.  
  677.     key = 0;
  678.     text[0] ='\0';
  679.     string[0] = '\0';
  680.     i = 220;
  681.  
  682.     do
  683.     {
  684.         i = i + 8;
  685.         XNextEvent(display,&circle_event);
  686.         count = XLookupString(&circle_event,text,10,&key,0);
  687.         text[count] = '\0';
  688.         if (key != XK_Return)
  689.             XDrawString(display,circle_window,circle_gc,
  690.                 i,105,text,1);
  691.         strcat(string,text);
  692.     }        while (key != XK_Return && circle_event.type == KeyPress);
  693.  
  694.     /* convert the string to an integer */
  695.  
  696.     circle_x = XOFF + strtol(string,NULL,10);
  697.  
  698.     /* Ask for the user to enter a y value */
  699.  
  700.     XDrawString(display,circle_window,circle_gc,
  701.         55,135,"Enter Y value of center: ",
  702.         25);
  703.  
  704.     key = 0;
  705.     text[0] ='\0';
  706.     string[0] = '\0';
  707.     i = 220;
  708.  
  709.     do
  710.     {
  711.         i = i + 8;
  712.         XNextEvent(display,&circle_event);
  713.         count = XLookupString(&circle_event,text,10,&key,0);
  714.         text[count] = '\0';
  715.         if (key != XK_Return)
  716.             XDrawString(display,circle_window,circle_gc,
  717.                 i,135,text,1);
  718.         strcat(string,text);
  719.     }        while (key != XK_Return && circle_event.type == KeyPress);
  720.  
  721.     /* conver the string to an integer */
  722.  
  723.     circle_y = YOFF - strtol(string,NULL,10);
  724.  
  725.     XDrawString(display,circle_window,circle_gc,
  726.         75,180,"Press any key to Exit",22);
  727.  
  728.     XFlush(display);
  729.  
  730.     do 
  731.         XNextEvent(display,&circle_event);
  732.     while( circle_event.xbutton.window != circle_window);
  733.  
  734.     font = XLoadFont(display,"8x16");
  735.     XSetFont(display,circle_gc,font);
  736.  
  737.     XDestroyWindow(display,circle_window);
  738.  
  739.     XFlush(display);
  740.  
  741.     draw_circle(circle_radius,display,parent,parent_gc,circle_x,circle_y);
  742.  
  743.  
  744. }
  745.  
  746.  
  747. draw_circle(rad,display,parent,gc,xc,yc)
  748.  
  749. float rad;
  750. Display *display;
  751. Window parent;
  752. int xc;
  753. int yc;
  754.  
  755. {
  756.  
  757.     float dtheta;
  758.     float ct;
  759.     float st;
  760.     float x=0;
  761.     float y=0;
  762.     float xtemp;
  763.     int tempx;
  764.     int tempy;
  765.     int i;
  766.  
  767.     XFlush(display);
  768.  
  769.  
  770.     XSetBackground(display,gc,white);
  771.     XSetForeground(display,gc,black);
  772.  
  773.     /* Draw x and y axis */
  774.  
  775.     XDrawLine(display,parent,gc,XOFF,0,XOFF,YOFF*2);
  776.     XDrawLine(display,parent,gc,0,YOFF,XOFF*2,YOFF);
  777.  
  778.     /* Draw notches in x and y axis */
  779.  
  780.     for (i=25; i<YOFF*2; i=i+25)
  781.         XDrawLine(display,parent,gc,
  782.             XOFF-3,i,XOFF+3,i);
  783.  
  784.     for (i=25; i<XOFF*2; i= i+25)
  785.         XDrawLine(display,parent,gc,
  786.             i,YOFF-3,i,YOFF+3);
  787.  
  788.  
  789.  
  790.     dtheta = 1/rad;
  791.  
  792.     ct = cos(dtheta);
  793.     st = sin(dtheta);
  794.  
  795.     x = 0;
  796.     y = rad;
  797.  
  798.     while (y >= x)
  799.     {
  800.  
  801.  
  802.         tempx = xc +x;
  803.         tempy = yc + y * ASPECT_RATIO;
  804.  
  805.         XDrawPoint(display,parent,gc,tempx,tempy);
  806.  
  807.         tempx = xc - x;
  808.  
  809.         XDrawPoint(display,parent,gc,tempx,tempy);
  810.  
  811.         tempx = xc + x;
  812.         tempy = yc - y * ASPECT_RATIO;
  813.  
  814.         XDrawPoint(display,parent,gc,tempx,tempy);
  815.  
  816.         tempx = xc - x;
  817.  
  818.         XDrawPoint(display,parent,gc,tempx,tempy);
  819.  
  820.         tempx = xc + y;
  821.         tempy = yc + x * ASPECT_RATIO;
  822.  
  823.         XDrawPoint(display,parent,gc,tempx,tempy);
  824.  
  825.         tempx = xc - y;
  826.  
  827.         XDrawPoint(display,parent,gc,tempx,tempy);
  828.  
  829.         tempx = xc + y;
  830.         tempy = yc - x * ASPECT_RATIO;
  831.  
  832.         XDrawPoint(display,parent,gc,tempx,tempy);
  833.  
  834.         tempx = xc - y;
  835.  
  836.         XDrawPoint(display,parent,gc,tempx,tempy);
  837.  
  838.         xtemp = x;
  839.         x = (x*ct - y *st);
  840.         y = (y*ct + xtemp*st);
  841.  
  842.  
  843.     }
  844.  
  845. }
  846.  
  847. /* clear the screen of the old figures and reset everything */
  848.  
  849.  
  850. process_reset(display,parent,child,parent_gc,child_gc)
  851.  
  852.  
  853. Display *display;
  854. Window parent,child;
  855. GC parent_gc,child_gc;
  856. {
  857.  
  858.     int i;
  859.  
  860.     /* flash the reset button */
  861.  
  862.     XClearWindow(display,child);
  863.     XFillRectangle(display,child,parent_gc,0,0,100,25);
  864.     XDrawImageString(display,child,child_gc,
  865.         25,20,reset_str,strlen(reset_str));
  866.     XFlush(display);
  867.     for (i=0; i<1000; i++)
  868.         XNoOp(display);
  869.     XClearWindow(display,child);
  870.     XDrawImageString(display,child,parent_gc,
  871.         25,20,reset_str,strlen(reset_str));
  872.  
  873.     XClearWindow(display,parent);
  874.  
  875.  
  876. }
  877.  
  878.