Introduction to the Figure Package - TeX Sample.
Sample Code Yielding a Screen Image and Files for Inclusion in a TeX Document.
Here is some sample code that produces a PostScript file named
texStep.ps and a label file named texStep.lbl when run as an application
(Java applets cannot create files - for security reasons)
and that yields a screen image when run as an applet.
/* File: texStep.java */
import java.applet.* ;
import java.awt.* ;
import figPac.* ;
public class texStep extends Applet {
static void prepareFigure(Figure canvas) {
canvas.limits(-1,-1,4,4) ;
canvas.append(new fAxes() ) ;
canvas.fTeXlabel(0, 4.1, "bc","$s(x)$","s(x)") ;
canvas.fTeXlabel(4.1,0,"lc","$x$","x") ;
canvas.append(new fCurve(new step(.5,1,3)) ) ;
}
public void init() {
Figure canvas = new Figure(this,5,5) ;
this.add(canvas) ;
canvas.useZoom = true ;
canvas.useDrag = true ;
canvas.showCoords =true ;
prepareFigure(canvas) ;
canvas.toScreen() ;
}
public static void main(String argv[]) {
Figure canvas = new Figure(5,5) ;
prepareFigure(canvas) ;
canvas.toPsFile("texStep.ps") ;
canvas.toLblFile("texStep.lbl") ;
System.exit(0) ;
}
}
class step implements S2S {
double location = 0 ;
double left_height = 0 ;
double right_height = 1 ;
public step() {
}
public step(double location, double left_height, double right_height) {
this.location = location;
this.left_height = left_height ;
this.right_height = right_height ;
}
public double map(double t) {
if ( t>location) return right_height ;
else return left_height ;
}
}
To compile this program you would
save it to a file named texStep.java and then execute
javac texStep.java
To get a screen image you would also create a file called texStep.html
containing
<HEAD><TITLE>Figure Test Program</TITLE></HEAD>
<BODY>
<H1>Figure Test Program </H1>
<P>
<APPLET code="texStep.class" width=500 height=500></APPLET>
</BODY>
and then execute
appletviewer texStep.html &
To, instead, create the PostScript and label files you would, after
compiling texStep.java, execute
java texStep
To embed the resulting figure in a TeX document you would