FileDocCategorySizeDatePackage
TextureAnim.javaAPI DocExample13974Wed Aug 08 15:13:48 BST 2001demos.Paint

TextureAnim

public class TextureAnim extends AnimatingControlsSurface
TexturePaint animation with controls for transformations.

Fields Summary
public static final Color
colorblend
protected static BufferedImage
textureImg
protected int
bNum
protected int
tilesize
private boolean
newtexture
private TexturePaint
texture
private Rectangle
tilerect
private boolean
bouncesize
private boolean
bouncerect
private boolean
rotate
private boolean
shearx
private boolean
sheary
private boolean
showanchor
private boolean
quality
private AnimVal
w
private AnimVal
h
private AnimVal
x
private AnimVal
y
private AnimVal
rot
private AnimVal
shx
private AnimVal
shy
private static Image[]
img
Constructors Summary
public TextureAnim()

    

      
        img[0] = getImage("duke.gif");   // 8 bit gif
        img[1] = getImage("duke.png");   // 24 bit png

        textureImg = makeImage(32, 0);
        tilesize = textureImg.getWidth();
        w = new AnimVal(0, 200, 3, 10, tilesize);
        h = new AnimVal(0, 200, 3, 10, tilesize);
        x = new AnimVal(0, 200, 3, 10, 0);
        y = new AnimVal(0, 200, 3, 10, 0);
        rot = new AnimVal(-360, 360, 5, 15, 0);
        shx = new AnimVal(-50, 50, 3, 10, 0);
        shy = new AnimVal(-50, 50, 3, 10, 0);
        tilerect = new Rectangle(x.getInt(), y.getInt(),
                                 w.getInt(), h.getInt());
        texture = new TexturePaint(textureImg, tilerect);
        setControls(new Component[] { new DemoControls(this) });
    
Methods Summary
public static voidmain(java.lang.String[] argv)

        createDemoFrame(new TextureAnim());
    
private java.awt.image.BufferedImagemakeGIFImage(int d)

        BufferedImage bi = new BufferedImage(d, d, BufferedImage.TYPE_INT_RGB);
        Graphics2D big = bi.createGraphics();
        big.drawImage(img[0], 0, 0, d, d, new Color(204, 204, 255), null);
        return bi;
    
protected java.awt.image.BufferedImagemakeImage(int size, int num)

        newtexture = true;
        switch (bNum = num) {
            case 0 : return makeRGBImage(size);
            case 1 : return makeGIFImage(size);
            case 2 : return makePNGImage(size);
        }
        return null;
    
private java.awt.image.BufferedImagemakePNGImage(int d)

        BufferedImage bi = new BufferedImage(d, d, BufferedImage.TYPE_INT_RGB);
        Graphics2D big = bi.createGraphics();
        big.drawImage(img[1], 0, 0, d, d, Color.lightGray, null);
        return bi;
    
private java.awt.image.BufferedImagemakeRGBImage(int size)

        BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
        Graphics2D big = bi.createGraphics();
        big.setColor(Color.white);
        big.fillRect(0, 0, size, size);
        for (int j = 0; j < size; j++) {
            float red = j / (float) size;
            for (int i = 0; i < size; i++) {
                float green = i / (float) size;
                big.setColor(new Color(1.0f - red, 1.0f - green, 0.0f, 1.0f));
                big.drawLine(i, j, i, j);
            }
        }
        return bi;
    
public voidrender(int width, int height, java.awt.Graphics2D g2)


        g2.translate(width/2, height/2);
        if (rotate) {
            rot.anim();
            g2.rotate(Math.toRadians(rot.getFlt()));
        } else {
            rot.set(0);
        }
        if (shearx) {
            shx.anim();
            g2.shear(shx.getFlt()/100, 0.0f);
        } else {
            shx.set(0);
        }
        if (sheary) {
            shy.anim();
            g2.shear(0.0f, shy.getFlt()/100);
        } else {
            shy.set(0);
        }
        g2.setPaint(texture);
        g2.fillRect(-1000, -1000, 2000, 2000);
        if (showanchor) {
            g2.setColor(Color.black);
            g2.setColor(colorblend);
            g2.fill(tilerect);
        }
    
public voidreset(int width, int height)

        x.newlimits(-width/4, width/4 - w.getInt());
        y.newlimits(-height/4, height/4 - h.getInt());
    
public voidstep(int width, int height)

        if (tilesize != textureImg.getWidth()) {
            tilesize = textureImg.getWidth();
        }
        if (bouncesize) {
            w.anim();
            h.anim();
            x.newlimits(-width/4, width/4 - w.getInt());
            y.newlimits(-height/4, height/4 - h.getInt());
        } else {
            if (w.getInt() != tilesize) {
                w.set(tilesize);
                x.newlimits(-width/4, width/4 - w.getInt());
            }
            if (h.getInt() != tilesize) {
                h.set(tilesize);
                y.newlimits(-height/4, height/4 - h.getInt());
            }
        }
        if (bouncerect) {
            x.anim();
            y.anim();
        }
        if (newtexture ||
            x.getInt() != tilerect.x || y.getInt() != tilerect.y ||
            w.getInt() != tilerect.width || h.getInt() != tilerect.height)
        {
            newtexture = false;
            int X = x.getInt();
            int Y = y.getInt();
            int W = w.getInt();
            int H = h.getInt();
            tilerect = new Rectangle(X, Y, W, H);
            texture = new TexturePaint(textureImg, tilerect);
        }