/* * SharkLine.java * A java program to make a shark line, similar to
, but with fin * Usage: * * * Ken Shirriff ken.shirriff@eng.sun.com * */ import java.awt.*; import java.awt.image.*; import java.io.*; import java.net.*; import java.applet.Applet; public class SharkLine extends java.applet.Applet implements Runnable { // Double buffer for output Image outimage; Graphics outgraphics; // Animation thread Thread sharkthread = null; // Parameters for the applet and fin sizes int width = 500; int delay = 60; int maxfinheight=5, offset=1; int height = 10; // pixels, image, color model, and colors for the line image int pix[]; Image line_img; IndexColorModel icm; byte r[] = new byte[3]; byte g[] = new byte[3]; byte b[] = new byte[3]; // Start up the applet public void init() { int i,j; if (getParameter("width") != null) { width = Integer.parseInt(getParameter("width")); } if (getParameter("height") != null) { height = Integer.parseInt(getParameter("height")); } if (getParameter("delay") != null) { delay = Integer.parseInt(getParameter("delay")); } // color 0 is the screen background r[0] = (byte) 192; g[0] = (byte) 192; b[0] = (byte) 192; // color 1 is the dark part of the line r[1] = (byte) 112; g[1] = (byte) 112; b[1] = (byte) 112; // color 2 is the light part of the line r[2] = (byte) 231; g[2] = (byte) 231; b[2] = (byte) 231; icm = new IndexColorModel(8,3,r,g,b); // Fill pix with the appropriate pixels for a shadowed line pix = new int[width*height]; for (i=0;i=maxfinheight) { goingup=false; } } else if (goingdown) { // Fin going down finheight--; if (finheight<0) { goingdown=false; visiblefin = false; } } if (right) { // Fin moving to the right x++; } else { // Fin moving to the left x--; } // Turn at edge or randomly if (x>=width-10 || x<=10 || Math.random()<.03) { cnt--; if (cnt==0) { goingdown = true; } else { right = !right; } } // Animation delay try { sharkthread.sleep(delay); } catch (Exception e) { } } } } public String getAppletInfo() { return "SharkLine by Ken Shirriff shirriff@eng.sun.com"; } public String[][] getParameterInfo() { String [][] info = { {"width ","int ", "image width"}, {"height ","int ", "image height"}, {"delay ","int ", "delay"}, }; return info; } } // SharkLine