FileDocCategorySizeDatePackage
Tree.javaAPI DocExample4349Wed Aug 08 15:13:48 BST 2001demos.Fonts

Tree

public class Tree extends AnimatingSurface
Transformation of characters.

Fields Summary
private char
theC
private Character
theT
private Character
theR
static Font
theFont
static double
Twidth
static double
Rwidth
static double
FontHeight
static Color[]
colors
Constructors Summary
public Tree()



      
        setBackground(Color.white);
    
Methods Summary
public static voidmain(java.lang.String[] argv)

        createDemoFrame(new Tree());
    
public voidrender(int w, int h, java.awt.Graphics2D g2)

        int mindim = Math.min(w, h);
        AffineTransform at = new AffineTransform();
        at.translate((w - mindim) / 2.0,
                     (h - mindim) / 2.0);
        at.scale(mindim, mindim);
        at.translate(0.5, 0.5);
        at.scale(0.3, 0.3);
        at.translate(-(Twidth + Rwidth), FontHeight / 4.0);
        g2.transform(at);
        tree(g2, mindim * 0.3, 0);

    
public voidreset(int w, int h)

 
public voidstep(int w, int h)

        setSleepAmount(4000);
        theT = new Character(theC = ((char) ((int) theC + 1)));
        theR = new Character((char) ((int) theC + 1));
        if (theR.compareTo(new Character('z")) == 0) {
            theC = 'A";
        }
    
public voidtree(java.awt.Graphics2D g2d, double size, int phase)



            
        g2d.setColor(colors[phase % 3]);
        new TextLayout(theT.toString(),theFont,g2d.getFontRenderContext()).draw(g2d, 0.0f, 0.0f);
        if (size > 10.0) {
            AffineTransform at = new AffineTransform();
            at.setToTranslation(Twidth, -0.1);
            at.scale(0.6, 0.6);
            g2d.transform(at);
            size *= 0.6;
            new TextLayout(theR.toString(),theFont, g2d.getFontRenderContext()).draw(g2d, 0.0f, 0.0f);
            at.setToTranslation(Rwidth+0.75, 0);
            g2d.transform(at);
            Graphics2D g2dt = (Graphics2D) g2d.create();
            at.setToRotation(-Math.PI / 2.0);
            g2dt.transform(at);
            tree(g2dt, size, phase + 1);
            g2dt.dispose();
            at.setToTranslation(.75, 0);
            at.rotate(-Math.PI / 2.0);
            at.scale(-1.0, 1.0);
            at.translate(-Twidth, 0);
            g2d.transform(at);
            tree(g2d, size, phase);
        }
        g2d.setTransform(new AffineTransform());