//******************************************************************************** // CountDown.java // // "CountDown" // // 1999 Maeda Mameo ( http://hw001.gate01.com/frog/ ) //******************************************************************************** import java.applet.Applet; import java.awt.Color; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Image; import java.awt.image.ImageObserver; import java.awt.image.MemoryImageSource; import java.awt.image.PixelGrabber; //import java.util.Date; import java.util.GregorianCalendar; public class CountDown extends Applet implements ImageObserver, Runnable{ private final String NUMBERFIGURE[] = { "3000000000300000000030000000003000000000300000000030000000003000000000300000000030000000003000000000", "30000000003000006e0030000000003006eff900300000000030001e1000300004f400300d51000030008500003000000000", "30000efd0030000bfe0030007dc000300fd6bf403000000d7030008fec8030006fe000306fffff60301ffff5003000026000", "3000efff9030000ef7003006fefc003000002f40300002efe03000dfeec03001fd000030ce12bf9030de00df00300efff200", "300df10ec030000bf000300dd0ae0030000dfe0030007fefb03000fa0000300dfc2000308800fd0030ec000de030ef6afb00", "306f600fa030000fc000300000ed0030002ff400300cfb7f103002f91000300feefc0030000de00030bf7cff4030f7008f00", "30ed004f203000bf000030000bf20030c102df0030ef70ee003000eff600306f008f0030009f3000300dff800030f6007f00", "30f600ee003000ec00003000df600030ee001f1039fffdf400300000cf00302f208f103000fb0000306fff000030ee8efd00", "32f20ef10030dfffd000301ffb6200302fdcef003016afffd0300000df00300fdcfc00300df0000032fb0f6000302efff100", "30efff20003000044000304fffff603007eed10030001f744030001df6003005ff8000307f6000003cf01f900030006f8000", "301b6000003000000000300000020030000000003000cf00003000ef4000300000000030ed0000003dfafe00003000fd0000", "3000000000300000000030000000003000000000300035000030001000003000000000301000000030efd000003009f00000" }; private Image imageOff, imageArg; private Graphics gOff; private Thread theThread; private boolean isLoading; //******************************************************************************** //******************************************************************************** public void init(){} public void start(){ theThread = new Thread( this); theThread.start();} public void stop(){ theThread.stop(); theThread = null;} public void update( Graphics g){ paint( g);} public void paint( Graphics g){ g.drawImage( imageOff, 0, 0, this);} public boolean imageUpdate( Image img, int infoflags, int x, int y, int width, int height){ if( img == imageArg && ( infoflags & ImageObserver.ALLBITS) != 0){ isLoading = false; return false; } return true; } //******************************************************************************** //******************************************************************************** public void run(){ int a, b, i, j, k, x, y, v, w, z; int colorArg, theW, theH; int src[], mix[]; long targetTime, n; final int MAXFPS = 20, TIMEMILLISNUM = 200; int timeMillisPointer; long t, timeMillis[]; boolean isShake; Dimension d; FontMetrics FM; GregorianCalendar c; Image imageMix; String s, fpsString; d = getSize(); theW = d.width; theH = d.height; imageOff = createImage( theW, theH); gOff = imageOff.getGraphics(); FM = gOff.getFontMetrics(); isLoading = true; imageArg = getImage( getCodeBase(), getParameter( "image")); if( prepareImage( imageArg, this)) isLoading = false; s = "loading."; while( isLoading){ gOff.setColor( Color.gray); gOff.fillRect( 0, 0, theW, theH); repaint(); sleeper( 200); gOff.setColor( Color.black); gOff.drawString( s, ( theW - FM.stringWidth( s)) / 2, theH / 2); repaint(); sleeper( 500); } gOff.drawImage( imageArg, 0, 0, this); src = new int[ 98 * 14]; x = Integer.parseInt( getParameter( "x")); y = Integer.parseInt( getParameter( "y")); try{ new PixelGrabber( imageArg, x, y, 98, 14, src, 0, 98).grabPixels();} catch( InterruptedException e){}; s = getParameter( "target"); if( s == null) s = "20000101000000"; c = new GregorianCalendar(); c.set( Integer.parseInt( s.substring( 0, 4)), Integer.parseInt( s.substring( 4, 6)) - 1, Integer.parseInt( s.substring( 6, 8)), Integer.parseInt( s.substring( 8, 10)), Integer.parseInt( s.substring( 10, 12)) ); targetTime = c.getTime().getTime(); s = getParameter( "color"); if( s == null) s = "333333"; colorArg = Integer.parseInt( s, 16); s = getParameter( "shake"); isShake = "on".equals( s); mix = new int[ 98 * 14]; timeMillisPointer = 0; timeMillis = new long[ TIMEMILLISNUM]; for( i = 0; i < TIMEMILLISNUM; i++) timeMillis[ i] = 1000L; Thread thisThread = Thread.currentThread(); while( theThread == thisThread){ t = System.currentTimeMillis(); for( i = 0; i < 98 * 14; i++) mix[ i] = src[ i]; n = targetTime - System.currentTimeMillis(); if( n < 0) n = 0; for( i = 0; i < 12; i++){ if( isShake){ v = (int)( 2 * Math.random()); w = (int)( 2 * Math.random()); } else { v = w = 1;} a = (int)( n / Math.pow( 10, ( 12 - i)) % 10); for( j = 0; j < 12; j++){ for( k = 0; k < 8; k++){ z = v + i * 8 + k + ( w + j) * 98; b = Integer.parseInt( NUMBERFIGURE[ j].substring( 1 + a * 10 + k, 1 + a * 10 + k + 1), 16); mix[ z] = 0xff000000 + ( ( b * ( colorArg & 0xff0000) + ( 15 - b) * ( src[ z] & 0xff0000)) / 15 & 0xff0000) + ( ( b * ( colorArg & 0x00ff00) + ( 15 - b) * ( src[ z] & 0x00ff00)) / 15 & 0x00ff00) + ( ( b * ( colorArg & 0x0000ff) + ( 15 - b) * ( src[ z] & 0x0000ff)) / 15 & 0x0000ff); } } } imageMix = createImage( new MemoryImageSource( 98, 14, mix, 0, 98)); prepareImage( imageMix, this); gOff.drawImage( imageMix, x, y, this); repaint(); timeMillis[ timeMillisPointer] = System.currentTimeMillis() - t; timeMillisPointer = ++timeMillisPointer % TIMEMILLISNUM; t = 0; for( i = 0; i < TIMEMILLISNUM; i++) t += timeMillis[ i]; t /= TIMEMILLISNUM; if( 1000L / MAXFPS > t){ sleeper( 1000L / MAXFPS - t); fpsString = MAXFPS + " frames / sec."; } else{ fpsString = 1000L / t + "." + 10000L / t % 10 + " frames / sec."; } showStatus( fpsString); } } private void sleeper( long t){ try{ theThread.sleep( t);} catch( InterruptedException e){};} }