//################################################################### // // Confetti.java (C)2000 amIbleeding.com // //################################################################### import java.applet.*; import java.awt.*; public class Rain extends Applet implements Runnable { private Thread m_snow = null; private Image offscreenImage; private String m_back = "none"; private Image backdrop; private Graphics offscreenGraphics; private Image frame; private int xSize; private int ySize; private int[] colors; private int amount; private Color[] cl={Color.white, Color.lightGray, Color.gray, Color.darkGray, Color.black}; private String[] cNames={"white","lightGray","gray","darkGray", "black"}; private int delay; private int angle; public String getAppletInfo() { return "Name: Confetti\r\n" + "Author: amIbleeding.com\r\n" + "Created with Microsoft Visual J++ Version 1.1"; } public void init() { String param; colors = new int[5]; amount=0; for (int t=0;t<5;t++) { param = getParameter(cNames[t]); if (param != null) colors[t] = Integer.parseInt(param); } for (int t=0;t<5;t++) { int tmp=colors[t]; colors[t]+=amount; amount+=tmp; } param = getParameter("back"); if (param != null) m_back = param; param = getParameter("frame"); if (param != null) frame = getImage(getCodeBase(),param); else frame=null; param = getParameter("delay"); if (param != null) delay= Integer.parseInt(param); else delay=100; param = getParameter("angle"); if (param != null) angle= Integer.parseInt(param); else angle=0; xSize=size().width; ySize=size().height; backdrop=getImage(getCodeBase(),m_back); offscreenImage = createImage(xSize,ySize); offscreenGraphics =offscreenImage.getGraphics(); System.out.println("Confetti (C)2000 amIbleeding.com"); //{{INIT_CONTROLS //}} } public void newimage() { offscreenGraphics.drawImage(backdrop,0,0,xSize,ySize,null); offscreenGraphics.setColor(Color.white); int onCl=0; int x1,y1; for(int i=0;i=colors[onCl]) { onCl++; offscreenGraphics.setColor(cl[onCl]); } x1=(int)(Math.random()*xSize); y1=(int)(Math.random()*ySize); offscreenGraphics.drawLine(x1,y1,x1+2*angle,y1+4); } if (frame != null) { offscreenGraphics.drawImage(frame,0,0,xSize,ySize,null); } } public void destroy() { offscreenGraphics.dispose(); } public void paint(Graphics g) { g.drawImage(offscreenImage,0,0,this); } public void update(Graphics g) { paint(g); } public void start() { if (m_snow == null) { m_snow = new Thread(this); m_snow.start(); } } public void stop() { if (m_snow != null) { m_snow.stop(); m_snow = null; } } public void run() { MediaTracker mt = new MediaTracker(this); mt.addImage(backdrop,0); if (frame!=null) { mt.addImage(frame,0); } try { mt.waitForAll(); } catch (Exception e) {} while (true) { try { long nw=System.currentTimeMillis(); newimage(); repaint(); long tm=delay-(System.currentTimeMillis()-nw); if (tm<10) {tm=10;} Thread.sleep(tm); newimage(); } catch (InterruptedException e) { stop(); } } } //{{DECLARE_CONTROLS //}} }