/*
 * HelloWorld applet
 *
 * Compile this applet and use in a www document something like this:
 *
 * <center>
 * <applet code=HelloWorld.class width=450 height=100>
 * <param name=string value="Patrick's Applets">
 * <param name=sleep value="100">
 * </applet>
 * </center>
 *
 *
 * Note: this applet is always a fixed size and yuo may want to
 * change this based on the length of the strings you want to display.
 *
 * Patrick Worfolk
 * worfolk@geom.umn.edu
 * The Geometry Center, 1996
 *
 * It works for me, but other than that I make no claims about this code!
 *
 */
import java.applet.Applet;
import java.awt.*;
import java.lang.*;

public class HelloWorld extends Applet implements Runnable {
	Thread thread;
	StringBuffer buffer;
	double phase;
	double delta_phase = 0.2;
	Font font;
	int sleep = 100;

	public void init() {
		String param;

        	resize(450,100);
		phase = 0.0;
		buffer = new StringBuffer(getParameter("string"));
		param = getParameter("sleep");
		if (param != null)
		  sleep = Integer.valueOf(param).intValue();
		font = new Font("TimesRoman", Font.PLAIN, 24);

		repaint();
        }

	public String getAppletInfo() {
		return "HelloWorld by Patrick Worfolk";
	}

	public void start() {
		thread = new Thread(this);
		thread.start();
	}

	public void stop() {
		thread.stop();
	}

	public void destroy() {
	}

	public void run() {
		while (true) {
		try {Thread.currentThread().sleep(sleep);}
			catch (InterruptedException e) {}
			repaint();
		}
	}

	public final synchronized void update(Graphics g) {
		g.setColor(Color.white);
		g.fillRect(0,0,size().width, size().height);
		paint(g);
	}

        public void paint(Graphics g) {
		int i, len, cwidth, h = size().height;

		if (font != null) g.setFont(font);

		len = buffer.length();
		cwidth = font.getSize();
		g.setColor(Color.blue);
		for (i=0; i<len; i++) {
		  g.drawString(String.valueOf(buffer.charAt(i)),
			     (int) (cwidth*(i+1)+cwidth*Math.cos(1.7*phase-i)/5.0),
			     (int) (h/2.0+h/7.0*Math.sin(phase+i*2*Math.PI/len)));
		}
		phase += delta_phase;
        }
}

