import com.sun.java.swing.*; import java.awt.*; import java.awt.geom.*; /** An example of shear transformations with * Java2D in Java 1.2. * 1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/ */ public class Shear extends JPanel { private static double gap=10, width=100; private Rectangle2D.Double rect = new Rectangle2D.Double(gap, gap, 100, 100); public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D)g; g2d.clearRect(0, 0, getSize().width, getSize().height); for (int i=0; i<5; i++) { g2d.setPaint(Color.red); g2d.fill(rect); // Each new square gets 0.2 more x shear g2d.shear(0.2, 0.0); g2d.translate(2.0*gap + width, 0.0); } } public static void main(String[] args) { String title = "Shear: x shear ranges from 0.0 for the " + "leftmost 'square' to 0.8 for the " + "rightmost one."; WindowUtil.openInJFrame(new Shear(), (int)(20.0*gap + 5.0*width), (int)(5.0*gap + width), title); } }