00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00022 class mdp_postscript {
00023 public:
00024 enum {BOLD=10};
00025 FILE *fp;
00026 float X0, Y0, Z0;
00027 float X1, Y1, Z1;
00028 float c0, c1, c2;
00029 float scale;
00030 float alpha;
00031 mdp_postscript() {
00032 fp=0;
00033 scale=1;
00034 };
00035 mdp_postscript(char filename[]) {
00036 open(filename);
00037 };
00038 virtual ~mdp_postscript() {
00039 if (fp!=0) close();
00040 };
00041 FILE* open(char filename[]) {
00042 printf("Making frame: %s\n", filename);
00043 fp=fopen(filename, "w");
00044 if(fp!=0) fprintf(fp,"%%!PS-Adobe-3.0 EPSF-3.0\n");
00045 fflush(fp);
00046 return fp;
00047 };
00048 void close() {
00049 fprintf(fp,"showpage\n");
00050 fprintf(fp,"%%%%Trailer\n");
00051 fprintf(fp,"%%%%EOF\n");
00052 fflush(fp);
00053 fclose(fp);
00054 fp=0;
00055 };
00056 void size(float x0, float y0, float x1, float y1) {
00057 X0=x0; Y0=y0;
00058 X1=x1; Y1=y1;
00059 fprintf(fp,"%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", scale*x0, scale*y0, scale*x1, scale*y1);
00060 fprintf(fp,"%%%%EndComments\n");
00061 fflush(fp);
00062 };
00063 void line(float x0, float y0, float x1, float y1) {
00064 fprintf(fp,"%.2f %.2f %.2f setrgbcolor\n", c0,c1,c2);
00065 fprintf(fp,"%.2f %.2f moveto\n", scale*x0, scale*y0);
00066 fprintf(fp,"%.2f %.2f lineto\n", scale*x1, scale*y1);
00067 fprintf(fp,"stroke\n");
00068 fflush(fp);
00069 };
00070 void box(float x0, float y0, float x1, float y1, int fill=0) {
00071 if (fill==1) fprintf(fp,"stroke\n");
00072 fprintf(fp,"%.2f %.2f moveto\n", scale*x0, scale*y0);
00073 fprintf(fp,"%.2f %.2f lineto\n", scale*x0, scale*y1);
00074 fprintf(fp,"%.2f %.2f lineto\n", scale*x1, scale*y1);
00075 fprintf(fp,"%.2f %.2f lineto\n", scale*x1, scale*y0);
00076 fprintf(fp,"%.2f %.2f lineto\n", scale*x0, scale*y0);
00077 if (fill==1) fprintf(fp,"fill\n");
00078 fprintf(fp,"stroke\n");
00079 fflush(fp);
00080 };
00081 void arc(float x0, float y0, float r, float alpha, float beta) {
00082 fprintf(fp,"%.2f %.2f %.2f %.2f %.2f arc\n", scale*x0, scale*y0, scale*r, alpha, beta);
00083 fprintf(fp,"stroke\n");
00084 fflush(fp);
00085 };
00086 void circle(float x0, float y0, float r, int fill=0) {
00087 if (fill!=BOLD) fprintf(fp,"%.2f %.2f %.2f 0 360 arc\n", scale*x0, scale*y0, r);
00088 if (fill==1) fprintf(fp,"fill\n");
00089 if (fill==BOLD) {
00090 fprintf(fp,"1 -0.1 0.1 {\n");
00091 fprintf(fp,"/r exch def\n");
00092 fprintf(fp,"%.2f 1 r 0.5 mul sub mul ", c0);
00093 fprintf(fp,"%.2f 1 r 0.5 mul sub mul ", c1);
00094 fprintf(fp,"%.2f 1 r 0.5 mul sub mul ", c2);
00095 fprintf(fp,"setrgbcolor\n");
00096 fprintf(fp,"stroke\n");
00097 fprintf(fp,"%.2f %.2f %.2f r mul 0 360 arc fill\n", scale*x0, scale*y0, scale*r);
00098 fprintf(fp,"} for\n");
00099 };
00100 fflush(fp);
00101 };
00102 void pen(float size) {
00103 fprintf(fp,"%.2f setlinewidth\n", size);
00104 };
00105
00106 void color(float r, float g, float b) {
00107 fprintf(fp,"%.2f %.2f %.2f setrgbcolor\n", r,g,b);
00108 c0=r; c1=g; c2=b;
00109 fflush(fp);
00110 };
00111 void font(const char *text, int size) {
00112 fprintf(fp,"/%s findfont\n%i scalefont\nsetfont\n", text, size);
00113 fflush(fp);
00114 };
00115 void print(float x0, float y0, char text[]) {
00116 fprintf(fp,"%.2f %.2f moveto\n", scale*x0, scale*y0);
00117 fprintf(fp,"(%s) show\n", text);
00118 fprintf(fp,"stroke\n");
00119 fflush(fp);
00120 };
00121 };
00122