ClipAnimpublic class ClipAnim extends AnimatingControlsSurface Animated clipping of an image & composited shapes. |
Fields Summary |
---|
private static Image | dimg | private static Image | cimg | private static Color | redBlend | private static Color | greenBlend | private static BasicStroke | bs | static TexturePaint | texture | private AnimVal[] | animval | protected boolean | doObjects | private Font | originalFont | private Font | font | private GradientPaint | gradient | private int | strX | private int | strY | private int | dukeX | private int | dukeY |
Constructors Summary |
---|
public ClipAnim()
cimg = getImage("clouds.jpg");
dimg = getImage("duke.gif");
setBackground(Color.white);
animval[0] = new AnimVal(true);
animval[1] = new AnimVal(false);
animval[2] = new AnimVal(false);
setControls(new Component[] { new DemoControls(this) });
|
Methods Summary |
---|
public static void | main(java.lang.String[] argv)
createDemoFrame(new ClipAnim());
| public void | render(int w, int h, java.awt.Graphics2D g2)
GeneralPath p1 = new GeneralPath();
GeneralPath p2 = new GeneralPath();
for (int i = 0; i < animval.length; i++) {
if (animval[i].isSelected) {
double x = animval[i].x; double y = animval[i].y;
double ew = animval[i].ew; double eh = animval[i].eh;
p1.append(new Ellipse2D.Double(x, y, ew, eh), false);
p2.append(new Rectangle2D.Double(x+5, y+5, ew-10, eh-10),false);
}
}
if (animval[0].isSelected || animval[1].isSelected ||
animval[2].isSelected)
{
g2.setClip(p1);
g2.clip(p2);
}
if (doObjects) {
int w2 = w/2;
int h2 = h/2;
g2.drawImage(cimg, 0, 0, w2, h2, null);
g2.drawImage(dimg, dukeX, dukeY, null);
g2.setPaint(texture);
g2.fillRect(w2, 0, w2, h2);
g2.setPaint(gradient);
g2.fillRect(0, h2, w2, h2);
g2.setColor(Color.lightGray);
g2.fillRect(w2, h2, w2, h2);
g2.setColor(Color.red);
g2.drawOval(w2, h2, w2-1, h2-1);
g2.setFont(font);
g2.drawString("CLIPPING", strX, strY);
} else {
g2.setColor(Color.lightGray);
g2.fillRect(0, 0, w, h);
}
| public void | reset(int w, int h)
for (int i = 0; i < animval.length; i++) {
animval[i].reset(w, h);
}
gradient = new GradientPaint(0,h/2,Color.red,w*.4f,h*.9f,Color.yellow);
dukeX = (int) (w*.25-dimg.getWidth(this)/2);
dukeY = (int) (h*.25-dimg.getHeight(this)/2);
FontMetrics fm = getFontMetrics(originalFont);
double sw = fm.stringWidth("CLIPPING");
double sh = fm.getAscent()+fm.getDescent();
double sx = (w/2-30)/sw;
double sy = (h/2-30)/sh;
AffineTransform Tx = AffineTransform.getScaleInstance(sx, sy);
font = originalFont.deriveFont(Tx);
fm = getFontMetrics(font);
strX = (int) (w*.75 - fm.stringWidth("CLIPPING")/2);
strY = (int) (h*.72 + fm.getAscent()/2);
| public void | step(int w, int h)
for (int i = 0; i < animval.length; i++) {
if (animval[i].isSelected) {
animval[i].step(w, h);
}
}
|
|