// mas964 ps4 // .5 second animation connecting two mouseclicks import java.applet.*; import java.awt.*; import java.lang.Math; import java.lang.String; import TwoPointAnimator; public class TwoPointShort extends TwoPointAnimator { protected int pointDistance, maxDimension, minBlockSize, maxNumBlocks; public void drawFrame(int ms) { Graphics g = imageBuffer.getGraphics(); this.clearImageBuffer(); g.setColor(this.getForeground()); // draw blocks at either end int numBlocks = maxNumBlocks * ms / animationLength; int size = minBlockSize * 3 - 2 * minBlockSize * ms / animationLength; g.fillRect(x1 - size/2, y1 - size/2, size, size); g.fillRect(x2 - size/2, y2 - size/2, size, size); int i; for (i = 1; i < numBlocks; i++) { int x, y; x = x1 + (x2 - x1) * i / numBlocks; y = y1 + (y2 - y1) * i / numBlocks; g.fillRect(x - size/2, y - size/2, size, size); } repaint(); } // precalculate the distance between the two dots public void start() { if (numButtonsPressed == 2) { maxDimension= Math.max(imageBufferSize.width, imageBufferSize.height); pointDistance = (int)Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); minBlockSize = maxDimension / 75; maxNumBlocks = pointDistance / (minBlockSize * 2); } super.start(); } public void init() { this.setBackground(Color.white); this.setForeground(Color.black); super.init(); if (frameDelay == 0 || animationLength == 0) { frameDelay = 30; animationLength = 500; } } }