// mas964 ps4 // 2 second animation connecting two mouseclicks // draws nested circles going into the first click, out of the second // two circles are drawn each time to give overlapping frames // the circle's speed gets quadratically slower the smaller it is. import java.applet.*; import java.awt.*; import java.lang.Math; import java.lang.String; import TwoPointAnimator; public class TwoPointLong extends TwoPointAnimator { public void drawFrame(int ms) { int halfway = animationLength / 2; // time half is done int circleThickness = 3; int maxSize = Math.max(imageBufferSize.width, imageBufferSize.height); Graphics g = imageBuffer.getGraphics(); this.clearImageBuffer(); g.setColor(this.getForeground()); if (ms < halfway) { // draw a circle going in to the first click int size = maxSize * (halfway - ms) * (halfway - ms) / (halfway*halfway); thickCenteredCircle(g, x1, y1, size, circleThickness); // draw the next frame as well (gives nested circles) ms += frameDelay; size = maxSize * (halfway - ms) * (halfway - ms) / (halfway*halfway); thickCenteredCircle(g, x1, y1, size, circleThickness); } else { // draw circles going out of the second click // (have to draw the bigger circle first) ms += frameDelay; int size = maxSize * (ms - halfway) * (ms - halfway) / (halfway*halfway); thickCenteredCircle(g, x2, y2, size, circleThickness); ms -= frameDelay; size = maxSize * (ms - halfway) * (ms - halfway) / (halfway*halfway); thickCenteredCircle(g, x2, y2, size, circleThickness); } repaint(); } public void thickCenteredCircle(Graphics g, int x, int y, int radius, int thickness) { Color c = g.getColor(); g.fillOval(x - radius, y - radius, radius * 2 + 1, radius * 2 + 1); g.setColor(this.getBackground()); g.fillOval(x - (radius - thickness), y - (radius - thickness), (radius - thickness) * 2 + 1, (radius - thickness) * 2 + 1); g.setColor(c); } public void stop() { this.clearImageBuffer(); repaint(); super.stop(); } public void init() { this.setBackground(Color.white); this.setForeground(Color.black); super.init(); if (frameDelay == 0 || animationLength == 0) { frameDelay = 50; animationLength = 2000; } } }