/*************************************************** Program: SpaceWave.java ***************************************************/ import java.applet.Applet; import java.awt.*; import java.util.StringTokenizer; public class SpaceWave extends Applet implements Runnable{ Thread thread; Image offScreenImage; Graphics offScreenG; private int napTime; private int pauseTime; private int numStars; private double AmpMultiplier; private double Freq; private double Amp; private String FontName; private int FontSize; private int Middle; private Color bgColor; private int i, xPos; private String text[]; private Color textColor[]; private Star star[]; private Font font; private int strNum = 0; private int Sleep = -1; private int numStrings; private double theta = 0; private boolean Sleeping = false; private boolean starsOn = true; private int charWidth; public void init() { Integer intObj; int defaultNapTime = 50; int defaultPauseTime = 100; double defaultAmpMultiplier = 3; double defaultFreq = 3; int defaultNumStars = 10; int defaultFontSize = 12; String defaultFontName = "Courier"; String paramStr; bgColor = getColor(getParameter("bgcolor"), Color.black); setBackground(bgColor); if (getParameter("stars").equals("off")) starsOn = false; text = new String[15]; for (i = 0; i < 11; i++) text[i] = getParameter("text" + (i+1)); if (text[0] == null) { text[0] = "SpaceWave was written by Bill Oatman"; numStrings = 1; } else for (i = 0; i < 11; i++) if (text[i] != null) numStrings = i+1; textColor = new Color[15]; textColor[0] = new Color(0,255,0); textColor[1] = new Color(255,0,0); textColor[2] = new Color(0,0,255); textColor[3] = new Color(255,0,255); textColor[4] = new Color(0,255,255); textColor[5] = new Color(255,255,255); textColor[6] = new Color(128,0,0); textColor[7] = new Color(0,0,128); textColor[8] = new Color(0,128,0); textColor[9] = new Color(128,128,0); textColor[10] = new Color(0,128,128); try { intObj = new Integer(getParameter("naptime")); napTime = intObj.intValue(); } catch (Exception e) { napTime = defaultNapTime; } try { intObj = new Integer(getParameter("pausetime")); pauseTime = intObj.intValue(); } catch (Exception e) { pauseTime = defaultPauseTime; } try { intObj = new Integer(getParameter("numstars")); numStars = intObj.intValue(); } catch (Exception e) { numStars = defaultNumStars; } try { intObj = new Integer(getParameter("ampmultiplier")); AmpMultiplier = intObj.intValue(); } catch (Exception e) { AmpMultiplier = defaultAmpMultiplier; } try { intObj = new Integer(getParameter("frequency")); Freq = intObj.intValue(); } catch (Exception e) { Freq = defaultFreq; } try { intObj = new Integer(getParameter("fontsize")); FontSize = intObj.intValue(); } catch (Exception e) { FontSize = defaultFontSize; } FontName = getParameter("fontname"); if (FontName == null) { FontName = defaultFontName; } star = new Star[numStars]; for (i = 0; i < numStars; i++) star[i] = new Star(this.size().height, this.size().width); offScreenImage = createImage(this.size().width, this.size().height); offScreenG = offScreenImage.getGraphics(); offScreenG.setColor(bgColor); offScreenG.fillRect(0,0,this.size().width, this.size().height); font = new Font(FontName, Font.BOLD, FontSize); offScreenG.setFont(font); charWidth = offScreenG.getFontMetrics().charWidth('a'); xPos = this.size().width; Amp = this.size().height / AmpMultiplier; Middle = this.size().height / 2 +3 ; } private Color getColor(String c, Color defaultColor) { Color temp; if (c == null) temp = defaultColor; else try { temp = new Color(Integer.parseInt(c, 16)); } catch (NumberFormatException e) { temp = defaultColor; } return temp; } public void paint(Graphics g) { g.drawImage(offScreenImage,0,0,this); } public void update(Graphics g) { int i, x, y; int cWidth; int initOffset; int xoffset; char data[]; data = new char[255]; String s; offScreenG.setColor(bgColor); offScreenG.fillRect(0,0,this.size().width, this.size().height); if (starsOn) for (i = 0; i < numStars; i++) star[i].Update(offScreenG); offScreenG.setColor(textColor[strNum]); initOffset = xPos; xoffset = xPos; for (i = 0; i < text[strNum].length(); i++) { xoffset += charWidth + 1; if ((xoffset > 0) && (xoffset < this.size().width)) { y = (int)(Amp * (Math.sin((double)((i+theta)/Freq))) + Middle); data[0] = text[strNum].charAt(i); offScreenG.drawChars(data, 0, 1,xoffset,y); } } paint(g); theta += 0.4; if (Sleeping) { Sleep--; if (Sleep < 1) { Sleeping = false; xPos -= 2; initOffset -= 2; } } else xPos -= 2; if (!Sleeping) if ( Math.abs( (initOffset+xoffset)/2 - (this.size().width/2)) <2) { Sleep = pauseTime; Sleeping = true; } if (xoffset < 0) { xPos = this.size().width; Sleeping = false; strNum++; if (strNum == numStrings) strNum = 0; } } public void start() { if (thread == null) { thread = new Thread(this); thread.start(); } } public void run() { while (thread != null) { repaint(); try { Thread.sleep(napTime); } catch (Exception e) {} } } public void stop() { thread = null; } public void destroy() {} }