home *** CD-ROM | disk | FTP | other *** search
- /*
- UNIX plot graphics package
- "plot.c"
- Ver 1.0 ('89 8/2)
- (C) Mik
- * 89/09/25
- * ---- V2.4.0 distribution ----
- */
- #include "option.h"
- #ifdef UOP_GRAPHICS
-
- #include <stdio.h>
- #include <math.h>
- #include "graph.h"
- #define square(x) ((x)*(x))
-
- /* Current point address */
- static int Current_x;
- static int Current_y;
-
- /* Window */
- static int Low_Left_X = 0;
- static int Low_Left_Y = 0;
- static int High_Right_X = X_SIZE;
- static int High_Right_Y = Y_SIZE;
- static double X_rate = 1.0;
- static double Y_rate = 1.0;
-
- extern void point_conv();
-
- /* plot execution */
- void plot_move(x,y)
- int x,y;
- {
- point_conv(x,y,&Current_x,&Current_y);
- }
-
- void plot_cont(x,y)
- int x,y;
- {
- int rx,ry;
-
- point_conv(x,y,&rx,&ry);
- line(Current_x,Current_y,rx,ry);
- Current_x = rx;
- Current_y = ry;
- }
-
- void plot_point(x,y)
- int x,y;
- {
- point_conv(x,y,&Current_x,&Current_y);
- point(Current_x,Current_y);
- }
-
- void plot_line(x1,y1,x2,y2)
- int x1,y1,x2,y2;
- {
- int rx,ry;
-
- point_conv(x1,y1,&rx,&ry);
- point_conv(x2,y2,&Current_x,&Current_y);
- line(rx,ry,Current_x,Current_y);
- }
-
- void plot_box(x1,y1,x2,y2)
- int x1,y1,x2,y2;
- {
- int rx,ry;
-
- point_conv(x1,y1,&rx,&ry);
- point_conv(x2,y2,&Current_x,&Current_y);
- box(rx,ry,Current_x,Current_y);
- }
-
- void plot_boxfill(x1,y1,x2,y2)
- int x1,y1,x2,y2;
- {
- int rx,ry;
-
- point_conv(x1,y1,&rx,&ry);
- point_conv(x2,y2,&Current_x,&Current_y);
- boxfill(rx,ry,Current_x,Current_y);
- }
-
- void plot_label(str)
- char *str;
- {
- Current_x = label(Current_x,Current_y,str);
- }
-
- void plot_arc(xc,yc,xs,ys,xe,ye)
- int xc,yc,xs,ys,xe,ye;
- {
- int rxc,ryc,rxs,rys,jxe,jye;
- int rx,ry;
- double r,d,a,b;
-
- r = sqrt(square((double)(xs - xc))
- + square((double)(ys - yc)));
- d = sqrt(square((double)(xe - xc))
- + square((double)(ye - yc)));
- a = r / d;
- b = 1 - a;
- jxe = a * xe + b * xc;
- jye = a * ye + b * yc;
- rx = r * fabs(X_rate);
- ry = r * fabs(Y_rate);
- point_conv(xc,yc,&rxc,&ryc);
- point_conv(xs,ys,&rxs,&rys);
- point_conv(jxe,jye,&Current_x,&Current_y);
- arc(rxc,ryc,rx,ry,rxs,rys,Current_x,Current_y);
- }
-
- void plot_circle(xc,yc,r)
- int xc,yc,r;
- {
- int rx,ry;
-
- rx = r * fabs(X_rate);
- ry = r * fabs(Y_rate);
- point_conv(xc,yc,&Current_x,&Current_y);
- circle(Current_x,Current_y,rx,ry);
- }
-
- void plot_erase()
- {
- graph_clear();
- }
-
- void plot_linemod(mod)
- int mod;
- {
- linemod(mod);
- }
-
- void plot_colormod(mod)
- int mod;
- {
- colormod(mod);
- }
-
- void plot_space(llx,lly,hrx,hry)
- int llx,lly,hrx,hry;
- {
- Low_Left_X = llx;
- Low_Left_Y = lly;
- High_Right_X = hrx;
- High_Right_Y = hry;
- X_rate = S_SIZE/(double)(hrx - llx);
- Y_rate = S_SIZE/(double)(lly - hry);
- }
-
- static void point_conv(x,y,rx,ry)
- int x,y;
- int *rx,*ry;
- {
- #if X_SIZE > Y_SIZE
- *rx = x * X_rate + X_SIZE - S_SIZE;
- *ry = y * Y_rate + Y_SIZE;
- #else
- *rx = x * X_rate;
- *ry = y * Y_rate + Y_SIZE;
- #endif
- }
-
- #endif /* UOP_GRAPHICS */
-