import java.awt.*; import java.awt.geom.*; import java.util.Date; /** * An example for an animation based on on convex combinations of * control points of two objects (the letters D and C). * * @author Frank Klawonn * Last change 04.02.2005 */ public class DToCMorphing extends Frame { //Constructor public DToCMorphing() { //Enables the closing of the window. addWindowListener(new MyFinishWindow()); } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; //Use of antialiasing to have nicer lines. g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); //The lines should have a thickness of 3.0 instead of 1.0. BasicStroke bs = new BasicStroke(5.0f); g2d.setStroke(bs); //Control points for the letter D. int[] xd = new int[6]; //The index 0 is not used. int[] yd = new int[6]; //The index 0 is not used. xd[1] = 50; yd[1] = 50; xd[2] = 50; yd[2] = 450; xd[3] = 400; yd[3] = 250; xd[4] = 50; yd[4] = 450; xd[5] = 50; yd[5] = 250; //Control points for the letter C. int[] xc = new int[6]; //The index 0 is not used. int[] yc = new int[6]; //The index 0 is not used. xc[1] = 50; yc[1] = 250; xc[2] = 250; yc[2] = 50; xc[3] = 50; yc[3] = 50; xc[4] = 250; yc[4] = 450; xc[5] = 50; yc[5] = 450; //Both letters are composed of two quadratic curves. The first curve has //the first, third and second as control points, the second curve the //first, fifth and fourth point. QuadCurve2D.Double q1; QuadCurve2D.Double q2; //Draw the letter D. q1 = new QuadCurve2D.Double(xd[1],yd[1],xd[3],yd[3],xd[2],yd[2]); q2 = new QuadCurve2D.Double(xd[1],yd[1],xd[5],yd[5],xd[4],yd[4]); g2d.draw(q1); g2d.draw(q2); //Wait 1 second before starting the transformation from D to C. sustain(1000); //ArraysC for the convex combinations of the control point of D and C double x[] = new double[xc.length]; double y[] = new double[x.length]; double alpha; //Number of steps (frames) that the transform from D to C should take. int steps = 500; double stepsDouble = steps; //Number of steps as a Double-value to avoid //repeated casting. for (int i=1; i<=steps; i++) { alpha = i/stepsDouble; //Computation of the convex combinations for the five pairs of points. for (int j=1; j C"); f.setSize(270,470); f.setVisible(true); } }