Introduction to the Figure Package - PostScript File Sample.
Sample Code Yielding a PostScript File
Here is some sample code that produces a postscript file named
psRose.ps as output.
Note that Java applets cannot create files (for security reasons). So this
implementation must be an application. Also note that (for some reason that
I do not yet know) you must explicitly exit with "System.exit(0)".
/* File: psRose.java */
import java.io.* ;
import figPac.* ;
public class psRose {
public static void main(String argv[]) {
Figure canvas = new Figure(6,6) ;
canvas.limits(-300,-300,300,300) ;
canvas.append(new fAxes("x axis","y axis") ) ;
fSubFigure subfig= new fSubFigure() ;
subfig.append(new fCurve(new rose(200,3),
0,Math.PI,
fCurve.CLOSED+fCurve.FILLED)) ;
canvas.append(new fEnv("psFillGray", 0.8)) ;
canvas.append(subfig) ;
canvas.append(new fLabel(100,50,"cc","Petal")) ;
canvas.toPsFile("psRose.ps") ;
System.exit(0) ;
}
}
class rose implements S2V {
double radius ;
int noPetals ;
public rose(double radius, int noPetals) {
this.radius = radius ;
this.noPetals = noPetals ;
}
public double[] map(double t) {
double[] out = new double[2] ;
out[0] = radius*Math.cos(t)*Math.sin(noPetals*t) ;
out[1] = radius*Math.sin(t)*Math.sin(noPetals*t) ;
return out ;
}
}
To compile and execute this program and print the resulting file you would
save it to a file named psRose.java and then use
javac psRose.java
java psRose
lpr psRose.ps