Introduction to the Figure Package - Screen Sample.
Sample Code Yielding a Screen Image
Here is a sample figure just containing a set of axes, a label and
a subfigure consisting of a rose with three petals.
/* File: screenRose.java */
import java.applet.* ;
import java.awt.* ;
import figPac.* ;
public class screenRose extends Applet {
public void init() {
Figure canvas = new Figure(this,6,6) ;
this.add(canvas) ;
canvas.limits(-300,-300,300,300) ;
canvas.showCoords = true ;
canvas.useZoom = true ;
canvas.useDrag = true ;
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(subfig) ;
canvas.append(new fEnv("fillColor", Color.yellow)) ;
canvas.append(new fLabel(100,50,"cc","Petal")) ;
canvas.toScreen() ;
}
}
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 execute this you would have to save the above program to a file named
screenRose.java and you would also have to create a file called screenRose.html and
containing
<HEAD><TITLE>Figure Test Program</TITLE></HEAD>
<BODY>
<H1>A rose drawn to screen </H1>
<P>
<APPLET code="screenRose.class" width=600 height=600></APPLET>
</BODY>
You then compile and execute the program using
javac screenRose.java
appletviewer screenRose.html &