Java Reference
In-Depth Information
AffineTransform at
=
AffineTransform.getTranslateInstance (72, 0);
g2.transform (at);
// Create a rotation transform of 30 degrees CCW around
// the top left corner of the rectangle.
AffineTransform atx
=
AffineTransform.getRotateInstance (
—
Math.PI/6, 30, 20);
// Take the shape object and create a rotated version
Shape atShape
=
atx.createTransformedShape (shape1);
g2.draw (atShape);
// Another 72 unit shift.
g2.transform (at);
// Create a scaling transform
atx
=
AffineTransform.getScaleInstance (1.5, 1.5);
// Take the shape object and create a scaled version
atShape
=
atx.createTransformedShape (shape1);
g2.draw (atShape);
// Another 72 unit shift.
g2.transform (at);
// Create a shear transform
atx
=
AffineTransform.getShearInstance (0.0, 0.5);
// Take the shape object and create a sheared version
atShape
=
atx.createTransformedShape (shape1);
g2.draw (atShape);
// Another 72 unit shift.
g2.transform (at);
// Illustrate compound transforms
// First get a transform object
atx
=
new AffineTransform ();
// Then set to a shear transform
atx.setToShear (0.0, 0.5);
// and then rotate about the current origin
atx.rotate (-Math.PI/5, 40, 50);
// Now apply to the rectangle
atShape
=
atx.createTransformedShape (shape1);
g2.draw (atShape);
}
// paintComponent
}
// class TransformPanel
Search WWH ::
Custom Search