// mas964 ps5 import java.applet.*; import java.awt.*; import java.lang.Math; import java.lang.String; import StrokeAnimator; public class SpinStroke extends StrokeAnimator { // draw line segments for each recorded input. Rotate them // over time. public void drawFrame(int ms) { Graphics g = imageBuffer.getGraphics(); this.clearImageBuffer(); g.setColor(this.getForeground()); int i; if (numPoints > 0) { int length = 5; double theta; if (ms < 800) // pause the first 1.5 secs theta = 0; else theta = (double)(ms - 800) / 600.0; // radians! double costheta = Math.cos(theta); double sintheta = Math.sin(theta); // draw the line segment rotated for (i = 0; i < numPoints; i++) { int y1 = -length, y2 = length; // vertical line g.drawLine(x[i] + (int)(-y1 * sintheta), y[i] + (int)(y1 * costheta), x[i] + (int)(-y2 * sintheta), y[i] + (int)(y2 * costheta)); } } repaint(); } public void init() { this.setBackground(Color.white); this.setForeground(Color.black); super.init(); if (frameDelay == 0) { frameDelay = 100; } } }