home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / COMM / MISC / SRC26_2.ZIP / SRC / PLOT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-04  |  2.9 KB  |  168 lines

  1. /*
  2.     UNIX plot graphics package
  3.         "plot.c"
  4.         Ver 1.0   ('89 8/2)
  5.         (C) Mik
  6.  * 89/09/25
  7.  *    ---- V2.4.0 distribution ----
  8. */
  9. #include "option.h"
  10. #ifdef UOP_GRAPHICS
  11.  
  12. #include <stdio.h>
  13. #include <math.h>
  14. #include "graph.h"
  15. #define square(x) ((x)*(x))
  16.  
  17. /* Current point address */
  18. static    int    Current_x;
  19. static    int    Current_y;
  20.  
  21. /* Window */
  22. static    int    Low_Left_X = 0;
  23. static    int    Low_Left_Y = 0;
  24. static    int    High_Right_X = X_SIZE;
  25. static    int    High_Right_Y = Y_SIZE;
  26. static    double    X_rate = 1.0;
  27. static    double    Y_rate = 1.0;
  28.  
  29. extern void point_conv();
  30.  
  31. /* plot execution */
  32. void plot_move(x,y)
  33. int    x,y;
  34. {
  35.     point_conv(x,y,&Current_x,&Current_y);
  36. }
  37.  
  38. void plot_cont(x,y)
  39. int    x,y;
  40. {
  41.     int    rx,ry;
  42.  
  43.     point_conv(x,y,&rx,&ry);
  44.     line(Current_x,Current_y,rx,ry);
  45.     Current_x = rx;
  46.     Current_y = ry;
  47. }
  48.  
  49. void plot_point(x,y)
  50. int    x,y;
  51. {
  52.     point_conv(x,y,&Current_x,&Current_y);
  53.     point(Current_x,Current_y);
  54. }
  55.  
  56. void plot_line(x1,y1,x2,y2)
  57. int    x1,y1,x2,y2;
  58. {
  59.     int    rx,ry;
  60.  
  61.     point_conv(x1,y1,&rx,&ry);
  62.     point_conv(x2,y2,&Current_x,&Current_y);
  63.     line(rx,ry,Current_x,Current_y);
  64. }
  65.  
  66. void plot_box(x1,y1,x2,y2)
  67. int    x1,y1,x2,y2;
  68. {
  69.     int    rx,ry;
  70.  
  71.     point_conv(x1,y1,&rx,&ry);
  72.     point_conv(x2,y2,&Current_x,&Current_y);
  73.     box(rx,ry,Current_x,Current_y);
  74. }
  75.  
  76. void plot_boxfill(x1,y1,x2,y2)
  77. int    x1,y1,x2,y2;
  78. {
  79.     int    rx,ry;
  80.  
  81.     point_conv(x1,y1,&rx,&ry);
  82.     point_conv(x2,y2,&Current_x,&Current_y);
  83.     boxfill(rx,ry,Current_x,Current_y);
  84. }
  85.  
  86. void plot_label(str)
  87. char    *str;
  88. {
  89.     Current_x = label(Current_x,Current_y,str);
  90. }
  91.  
  92. void plot_arc(xc,yc,xs,ys,xe,ye)
  93. int    xc,yc,xs,ys,xe,ye;
  94. {
  95.     int    rxc,ryc,rxs,rys,jxe,jye;
  96.     int    rx,ry;
  97.     double    r,d,a,b;
  98.  
  99.     r  = sqrt(square((double)(xs - xc))
  100.             + square((double)(ys - yc)));
  101.     d  = sqrt(square((double)(xe - xc))
  102.             + square((double)(ye - yc)));
  103.     a  = r / d;
  104.     b  = 1 - a;
  105.     jxe = a * xe + b * xc;
  106.     jye = a * ye + b * yc;
  107.     rx = r * fabs(X_rate);
  108.     ry = r * fabs(Y_rate);
  109.     point_conv(xc,yc,&rxc,&ryc);
  110.     point_conv(xs,ys,&rxs,&rys);
  111.     point_conv(jxe,jye,&Current_x,&Current_y);
  112.     arc(rxc,ryc,rx,ry,rxs,rys,Current_x,Current_y);
  113. }
  114.  
  115. void plot_circle(xc,yc,r)
  116. int    xc,yc,r;
  117. {
  118.     int    rx,ry;
  119.  
  120.     rx = r * fabs(X_rate);
  121.     ry = r * fabs(Y_rate);
  122.     point_conv(xc,yc,&Current_x,&Current_y);
  123.     circle(Current_x,Current_y,rx,ry);
  124. }
  125.  
  126. void plot_erase()
  127. {
  128.     graph_clear();
  129. }
  130.  
  131. void plot_linemod(mod)
  132. int    mod;
  133. {
  134.     linemod(mod);
  135. }
  136.  
  137. void plot_colormod(mod)
  138. int    mod;
  139. {
  140.     colormod(mod);
  141. }
  142.  
  143. void plot_space(llx,lly,hrx,hry)
  144. int    llx,lly,hrx,hry;
  145. {
  146.     Low_Left_X = llx;
  147.     Low_Left_Y = lly;
  148.     High_Right_X = hrx;
  149.     High_Right_Y = hry;
  150.     X_rate = S_SIZE/(double)(hrx - llx);
  151.     Y_rate = S_SIZE/(double)(lly - hry);
  152. }
  153.  
  154. static    void point_conv(x,y,rx,ry)
  155. int    x,y;
  156. int    *rx,*ry;
  157. {
  158. #if X_SIZE > Y_SIZE
  159.     *rx = x * X_rate + X_SIZE - S_SIZE;
  160.     *ry = y * Y_rate + Y_SIZE;
  161. #else
  162.     *rx = x * X_rate;
  163.     *ry = y * Y_rate + Y_SIZE;
  164. #endif
  165. }
  166.  
  167. #endif /* UOP_GRAPHICS */
  168.