public class dragon extends Applet{
Affine f1,f2;
static final coordinate origin= new coordinate();
static int c1=255;
static int c2=0;
public void init(){
setBackground(Color.white);
f1=new Affine();
f1.rotate(Math.PI / 4);
f1.scale(Math.sqrt(0.5));
f2=new Affine();
f2.shift(-1.0, 0.0);
f2.rotate(Math.PI / 4);
f2.scale(Math.sqrt(0.5));
f2.shift(1.0, 0.0);
}
public void paint(Graphics g){
Affine t=new Affine();
trans(0,t,g);
}
public void trans(int n, Affine t, Graphics g){
if (n==14) {
int w[];
w= new int[2];
coordinate z = new coordinate();
z.transformed(origin,t);
z.map(w);
g.drawLine(w[0],w[1],w[0],w[1]);
}
else {
if (n==8) {
Color c= new Color(0,c1,c2);
g.setColor(c);
c1--;
c2++;
}
Affine m1= new Affine();
m1.mult(f1);
m1.mult(t);
trans(n+1,m1,g);
Affine m2= new Affine();
m2.mult(f2);
m2.mult(t);
trans(n+1,m2,g);
};
}
}
Class Affine, Class coordinate は,前ページのものと同じなので省いてあります。
この例では,色の強度が0から255までの数値で指定されることを前提としたコードになっています。
Javaに関する情報は, 日本サン JAVAガイド