org » gecode » gist » postscript
Diamond.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 package org.gecode.gist.postscript;
00039
00040 import java.io.Writer;
00041 import java.io.IOException;
00042
00043 public class Diamond extends Path {
00044 private int cx, cy, r;
00045 private PSColor outline;
00046 private PSColor fill;
00047
00048 public Diamond(int cx0, int cy0, int r0,
00049 PSColor outline0, PSColor fill0) {
00050 cx = cx0;
00051 cy = cy0;
00052 r = r0;
00053 outline = outline0;
00054 fill = fill0;
00055 }
00056
00057 void emit(Writer out) throws IOException {
00058 double c1x = (double) cx;
00059 double c1y = (double) cy;
00060 double c2x = c1x + (double) r;
00061 double c2y = c1y + (double) r;
00062 double c3x = c1x;
00063 double c3y = c1y + (double) (2*r);
00064 double c4x = c1x - (double) r;
00065 double c4y = c2y;
00066
00067 out.write("gsave\n");
00068 out.write(c1x+" "+c1y+" moveto "+c2x+" "+c2y+" lineto ");
00069 out.write(c3x+" "+c3y+" lineto "+c4x+" "+c4y+" lineto ");
00070 out.write(c1x+" "+c1y+" lineto\n");
00071 out.write(fill.r+" "+fill.g+" "+fill.b+" setrgbcolor\n");
00072 out.write("eofill\n");
00073 out.write(c1x+" "+c1y+" moveto "+c2x+" "+c2y+" lineto ");
00074 out.write(c3x+" "+c3y+" lineto "+c4x+" "+c4y+" lineto ");
00075 out.write(c1x+" "+c1y+" lineto\n");
00076 out.write("1 setlinejoin 1 setlinecap\n");
00077 out.write("1 setlinewidth\n");
00078 out.write("[] 0 setdash\n");
00079 out.write(outline.r+" "+outline.g+" "+outline.b+" setrgbcolor\n");
00080 out.write("stroke\n");
00081 out.write("grestore\n");
00082 }
00083
00084 BoundingBox bb() {
00085 return new BoundingBox(cx-r,cx+r,cy-r,cy+r);
00086 }
00087 }