// Spiral.java expanding and contracting spirals import java.awt.*; import java.awt.event.*; public class Spiral extends Frame { int height = 500; int width = 500; Spiral() { setTitle("Spiral"); setSize(width,height); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); } public void paint(Graphics g) { double dt = 0.1; double x1, x2, y1, y2, r, c; int xm = width/2; int ym = height/2; // draw text g.setColor(Color.red); g.drawString("r = c*t", 20, 50); g.drawString("x1 = r*Math.cos(t)", 20, 70); g.drawString("y1 = r*Math.sin(t)", 20, 90); c = 5.0; for(double t=10.0; t<30.0; t=t+dt) { r = c*t; x1 = r*Math.cos(t); y1 = r*Math.sin(t); r = c*(t+dt); x2 = r*Math.cos(t+dt); y2 = r*Math.sin(t+dt); g.drawLine((int)x1+xm, (int)y1+ym, (int)x2+xm, (int)y2+ym); } g.setColor(Color.blue); g.drawString("r = c/t", width/2, 50); g.drawString("x1 = r*Math.cos(t)", width/2, 70); g.drawString("y1 = r*Math.sin(t)", width/2, 90); c = 400.0; for(double t=10.0; t<30.0; t=t+dt) { r = c/t; x1 = r*Math.cos(t); y1 = r*Math.sin(t); r = c/(t+dt); x2 = r*Math.cos(t+dt); y2 = r*Math.sin(t+dt); g.drawLine((int)x1+xm, (int)y1+ym, (int)x2+xm, (int)y2+ym); } } public static void main(String args[]) { new Spiral(); } } // end Spiral.java