version 1.1, 2001/12/10 05:02:46 |
version 1.6, 2002/07/14 07:10:01 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/lib/glib,v 1.5 2002/07/14 03:57:24 takayama Exp $ */ |
/* $Id$ */ |
/* $Id$ */ |
|
|
/* Todo: |
|
1. Some functions should be moved to longname |
|
*/ |
|
|
|
/* #define CLIP 1 */ |
/* #define CLIP 1 */ |
/* #define DEBUG 1 */ |
/* #define DEBUG 1 */ |
#define LIST 4 |
#define LIST 4 |
|
|
/* General sugar functions */ |
def glib_floor(N) { |
def floor(N) { |
|
return(pari(floor,N)); |
return(pari(floor,N)); |
} |
} |
|
|
|
/* |
def join(A,B) { |
def join(A,B) { |
if (type(B) == 0) return(A); |
if (type(B) == 0) return(A); |
return(append(A,B)); |
return(append(A,B)); |
} |
} |
|
|
def eigenvalues(M) { |
def eigenvalues(M) { |
return(pari(eigen,M)); |
return(pari(eigen,M)); |
} |
} |
|
|
def roots(F) { |
def roots(F) { |
return(pari(roots,F)); |
return(pari(roots,F)); |
} |
} |
|
*/ |
|
|
/* ---------------------------------------------- */ |
/* ---------------------------------------------- */ |
def ox_get_errors(P) { |
def ox_get_errors(P) { |
Line 39 def reset_plot() { |
|
Line 35 def reset_plot() { |
|
ox_reset(Glib_process); |
ox_reset(Glib_process); |
print(" Done."); |
print(" Done."); |
} |
} |
|
Glib_ps = 0$ |
|
Glib_h = []$ |
Glib_canvas_x = 400$ |
Glib_canvas_x = 400$ |
Glib_canvas_y = 400$ |
Glib_canvas_y = 400$ |
Glib_xmin=0$ Glib_xmax=Glib_canvas_x$ |
Glib_xmin=0$ Glib_xmax=Glib_canvas_x$ |
Line 118 def glib_clear() { |
|
Line 116 def glib_clear() { |
|
clear_canvas(Glib_process,Glib_canvas); |
clear_canvas(Glib_process,Glib_canvas); |
} |
} |
|
|
|
/*&usage begin: glib_window(Xmin,Ymin,Xmax,Ymax) |
|
It generates a window with the left top corner [{Xmin},{Ymin}] and |
|
the right bottom corner [{Xmax},{Ymax}]. |
|
example: glib_window(-1,-1,10,10); |
|
end: */ |
def glib_window(Xmin,Ymin,Xmax,Ymax) { |
def glib_window(Xmin,Ymin,Xmax,Ymax) { |
extern Glib_xmin, Glib_xmax, Glib_ymin, Glib_ymax, |
extern Glib_xmin, Glib_xmax, Glib_ymin, Glib_ymax, |
Glib_canvas_x, Glib_canvas_y, Glib_process, Glib_canvas, |
Glib_canvas_x, Glib_canvas_y, Glib_process, Glib_canvas, |
Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag; |
Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag; |
if (Xmax <= Xmin) error("glib window: Invalid size"); |
if (Xmax <= Xmin) error("glib window: Invalid size"); |
if (Ymax <= Ymin) error("glib window: Invalid size"); |
if (Ymax <= Ymin) error("glib window: Invalid size"); |
|
glib_check_arg(Xmin,Ymin); glib_check_arg(Xmax,Ymax); |
Glib_xmin = Xmin; Glib_xmax = Xmax; |
Glib_xmin = Xmin; Glib_xmax = Xmax; |
Glib_ymin = Ymin; Glib_ymax = Ymax; |
Glib_ymin = Ymin; Glib_ymax = Ymax; |
Glib_xoffset = -Xmin; |
Glib_xoffset = -Xmin; |
Line 133 def glib_window(Xmin,Ymin,Xmax,Ymax) { |
|
Line 137 def glib_window(Xmin,Ymin,Xmax,Ymax) { |
|
if (Glib_canvas < 0) glib_open(); |
if (Glib_canvas < 0) glib_open(); |
} |
} |
|
|
|
def glib_check_arg(X,Y) { |
|
if (type(X) <= 1 && type(Y) <= 1) return 1; |
|
else { |
|
print("Error in glib: arguments ",0); |
|
print([X,Y],0); |
|
print(" are not numbers."); |
|
error("Invalid argument for glib_window, glib_putpixel, glib_line."); |
|
} |
|
} |
|
|
|
/*&usage begin: glib_putpixel(X,Y|color) |
|
It puts a pixel at [{X},{Y}] with {color} |
|
example: glib_putpixel(1,2 | color=0xffff00); |
|
end: */ |
def glib_putpixel(X,Y) { |
def glib_putpixel(X,Y) { |
extern Glib_process, Glib_canvas, |
extern Glib_process, Glib_canvas, |
Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag; |
Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag, Glib_ps; |
if (Glib_canvas < 0) glib_open(); |
if (Glib_canvas < 0) glib_open(); |
glib_check(); |
glib_check(); |
draw_obj(Glib_process,Glib_canvas, |
glib_check_arg(X,Y); |
[floor(Glib_xmag*(X+Glib_xoffset)), |
C = getopt(color); |
floor(Glib_ymag*(Y+Glib_yoffset))]); |
Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)), |
|
glib_floor(Glib_ymag*(Y+Glib_yoffset))]; |
|
if ( type(C) != -1 ) { |
|
draw_obj(Glib_process,Glib_canvas,Pos,C); |
|
if (Glib_ps) glib_history(["putpixel",Pos,C]); |
|
}else{ |
|
draw_obj(Glib_process,Glib_canvas,Pos); |
|
if (Glib_ps) glib_history(["putpixel",Pos,0]); |
|
} |
} |
} |
|
|
|
/*&usage begin: glib_line(X0,Y0,X1,Y1|color) |
|
It draw the line [{X0},{Y0}]-- [{X1},{Y1}]with {color} |
|
example: glib_line(0,0,5,3/2 | color=0xff00ff); |
|
end: */ |
def glib_line(X0,Y0,X1,Y1) { |
def glib_line(X0,Y0,X1,Y1) { |
extern Glib_xmag, Glib_ymag, Glib_xoffset, Glib_yoffset; |
extern Glib_xmag, Glib_ymag, Glib_xoffset, Glib_yoffset; |
glib_clip_line(floor(Glib_xmag*(X0+Glib_xoffset)), |
C = getopt(color); |
floor(Glib_ymag*(Y0+Glib_yoffset)), |
glib_check_arg(X0,Y0); |
floor(Glib_xmag*(X1+Glib_xoffset)), |
glib_check_arg(X1,Y1); |
floor(Glib_ymag*(Y1+Glib_yoffset))); |
glib_clip_line(glib_floor(Glib_xmag*(X0+Glib_xoffset)), |
|
glib_floor(Glib_ymag*(Y0+Glib_yoffset)), |
|
glib_floor(Glib_xmag*(X1+Glib_xoffset)), |
|
glib_floor(Glib_ymag*(Y1+Glib_yoffset)),C); |
} |
} |
|
|
def glib_clip_line(X0,Y0,X1,Y1) { |
def glib_clip_line(X0,Y0,X1,Y1,Color) { |
/* X0, Y0, X1, Y1 should be integers. |
/* X0, Y0, X1, Y1 should be integers. |
Coordinates are already translated. */ |
Coordinates are already translated. */ |
extern Glib_process, Glib_canvas, Glib_canvas_x, Glib_canvas_y; |
extern Glib_process, Glib_canvas, Glib_canvas_x, Glib_canvas_y, |
|
Glib_ps; |
if (Glib_canvas < 0) glib_open(); |
if (Glib_canvas < 0) glib_open(); |
|
|
#ifdef CLIP |
if (Glib_ps) { |
#ifdef DEBUG |
#ifdef DEBUG |
print(["clip_line",[X0,Y0,X1,Y1]]); |
print(["clip_line",[X0,Y0,X1,Y1]]); |
#endif |
#endif |
Line 193 def glib_clip_line(X0,Y0,X1,Y1) { |
|
Line 227 def glib_clip_line(X0,Y0,X1,Y1) { |
|
#ifdef DEBUG |
#ifdef DEBUG |
print([X0,Y0,X1,Y1]); |
print([X0,Y0,X1,Y1]); |
#endif |
#endif |
#endif |
} |
|
|
glib_check(); |
glib_check(); |
draw_obj(Glib_process,Glib_canvas, |
Pos = [glib_floor(X0),glib_floor(Y0),glib_floor(X1),glib_floor(Y1)]; |
[floor(X0),floor(Y0),floor(X1),floor(Y1)]); |
if ( type(Color) != -1 ) { |
|
draw_obj(Glib_process,Glib_canvas,Pos,Color); |
|
if (Glib_ps) glib_history(["line",Pos,Color]); |
|
}else{ |
|
draw_obj(Glib_process,Glib_canvas,Pos); |
|
if (Glib_ps) glib_history(["line",Pos,0]); |
|
} |
} |
} |
|
|
def glib_clip0_x(X0,Y0,X1,Y1,Clip) { |
def glib_clip0_x(X0,Y0,X1,Y1,Clip) { |
Line 239 def glib_clip1_y(X0,Y0,X1,Y1,Clip) { |
|
Line 279 def glib_clip1_y(X0,Y0,X1,Y1,Clip) { |
|
return([X0,Y0,X1+(Clip-Y1)*(X0-X1)/(Y0-Y1),Clip]); |
return([X0,Y0,X1+(Clip-Y1)*(X0-X1)/(Y0-Y1),Clip]); |
} |
} |
return([X0,Y0,X1,Y1]); |
return([X0,Y0,X1,Y1]); |
|
} |
|
|
|
/*&usage begin: glib_print(X,Y,Text|color) |
|
It put a string {Text} at [{X},{Y}] on the glib canvas. |
|
example: glib_print(100,100,"Hello Worlds" | color=0xff0000); |
|
end: */ |
|
def glib_print(X,Y,Text) { |
|
extern Glib_process, Glib_canvas, |
|
Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag, Glib_ps; |
|
if (Glib_canvas < 0) glib_open(); |
|
glib_check(); |
|
glib_check_arg(X,Y); |
|
if (type(Text) != 7) error("glib_print(X,Y,Text): Text must be a string."); |
|
C = getopt(color); |
|
Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)), |
|
glib_floor(Glib_ymag*(Y+Glib_yoffset))]; |
|
if ( type(C) != -1 ) { |
|
draw_string(Glib_process,Glib_canvas,Pos,Text,C); |
|
if (Glib_ps) glib_history(["print",Pos,Text,C]); |
|
}else{ |
|
draw_string(Glib_process,Glib_canvas,Pos,Text); |
|
if (Glib_ps) glib_history(["print",Pos,Text,0]); |
|
} |
|
} |
|
|
|
def glib_history(L) { |
|
extern Glib_h, Glib_canvas_x, Glib_canvas_y; |
|
if (L[0] == "putpixel" || L[0] == "print") { |
|
if (L[1][0] <= Glib_canvas_x && L[1][0] >= 0) { |
|
if (L[1][1] <= Glib_canvas_x && L[1][1] >= 0) |
|
Glib_h = cons(L,Glib_h); |
|
} |
|
}else { |
|
Glib_h = cons(L,Glib_h); |
|
} |
|
return 0; |
|
} |
|
|
|
/*&usage begin: glib_tops() |
|
If Glib_ps is set to 1, |
|
it returns a postscript program to draw the picture on the canvas. |
|
end: */ |
|
def glib_tops() { |
|
extern Glib_h; |
|
return glib_ps(Glib_h); |
|
} |
|
def glib_ps(L) { |
|
PS = ""; |
|
Prev_color = 0; |
|
/* Prolog */ |
|
PS += "%%!PS-Adobe-1.0\n"; |
|
PS += "%%BoundingBox: 0 0 " + |
|
rtostr(Glib_canvas_x) + " " + rtostr(Glib_canvas_y) + "\n"; |
|
PS += "%%Creator: This is generated by ifplot\n"; |
|
PS += "%%Title: ifplot\n"; |
|
PS += "%%EndComments: \n"; |
|
PS += "0.1 setlinewidth \n"; |
|
PS += "2 setlinecap \n"; |
|
PS += "2 setlinejoin \n"; |
|
PS += "/ifplot_putpixel { \n"; |
|
PS += " /yyy 2 1 roll def /xxx 2 1 roll def \n"; |
|
PS += " gsave newpath xxx yyy .5 0 360 arc \n"; |
|
PS += " fill grestore \n"; |
|
PS += "} def \n"; |
|
|
|
L = reverse(L); |
|
N = length(L); |
|
for (I=0; I<N; I++) { |
|
C = L[I]; |
|
if (C[length(C)-1] != Prev_color) { |
|
Prev_color = C[length(C)-1]; |
|
PS += rtostr(deval(ishift(Prev_color,16)/256)) + " " + |
|
rtostr(deval(iand(ishift(Prev_color,8),0xff)/256)) + " " + |
|
rtostr(deval(iand(Prev_color,0xff)/256)) + " setrgbcolor \n"; |
|
} |
|
if (C[0] == "putpixel") { |
|
PS += rtostr(C[1][0]) + " " + rtostr(C[1][1]) + " ifplot_putpixel \n"; |
|
} |
|
if (C[0] == "line") { |
|
PS += " newpath "; |
|
PS += rtostr(C[1][0]) + " " + rtostr(C[1][1]) + " moveto " + |
|
rtostr(C[1][2]) + " " + rtostr(C[1][3]) + " lineto stroke \n"; |
|
} |
|
if (C[0] == "print") { |
|
PS += "/Times-Roman findfont 10 scalefont setfont \n"; |
|
PS += rtostr(C[1][0]) + " " + rtostr(C[1][1]) + " moveto "; |
|
PS += "(" + C[2] + ") show \n"; |
|
} |
|
} |
|
|
|
/* Epilog */ |
|
PS += "0 0 0 setrgbcolor \n"; |
|
PS += "showpage \n"; |
|
|
|
return PS; |
} |
} |
end$ |
end$ |
|
|