//
/* munch.java --- rrs@isi.edu --- 05-28-96 */
/* Munching Squares is a neat display hack!!! this applet should provide about
12 hours of different displays before repeating. This version is for bitmap
displays and Xor¼s the pixels for a multi-pas display. Originally this
was five machine language instructions on the Dec PDP-1 */
import java.awt.*;
import java.applet.*;
public class munch9bw extends Applet implements Runnable
{
int wx, wy; // window width and heigth
int x, y, t;
int lim = 255;
Thread munchThread;
int delay = 10;
static boolean keepRunning;
Graphics myG;
Color frgclr, bkgclr, xorclr;
public void init( )
{
wx = 256;
wy = 256;
myG = this.getGraphics( );
Dimension d = size();
if (( d.width != wx ) || ( d.height != wy)) { resize( wx, wy); }
frgclr = Color.white;
bkgclr = Color.black;
xorclr = Color.blue;
setBackground( bkgclr );
setForeground( frgclr );
keepRunning = true;
String spdstr = "10";
delay = Integer.parseInt( spdstr );
}
public void start( )
{
keepRunning = true;
munchThread = new Thread(this);
myG.setColor( frgclr );
myG.fillRect( 0, 0, wx-1, wy-1);
try {Thread.currentThread().sleep(2*delay);}
catch (InterruptedException e){}
munchThread.start();
}
public void stop()
{
keepRunning = false;
munchThread.stop();
}
public void run ( )
{
int sw = 1, sdel = 300;
int x, y;
boolean fullcycle = true;
t=0;
try {Thread.currentThread().sleep(sdel);}
catch (InterruptedException e){}
while( keepRunning )
{
showStatus( "" + sw );
t = ( t + sw ) & 255;
if( t == 0 )
{
fullcycle = ! fullcycle;
if ( fullcycle ) { sw++; sw &= 255; }
}
update( myG );
Thread.currentThread().yield();
}
}
public void update( Graphics g )
{
paint( g );
}
public void paint ( Graphics g )
{
int lim = 255;
g.setXORMode( xorclr );
for( int x = 0; x <= lim; x++)
{
g.drawLine( x, x^t, x, x^t );
}
g.setPaintMode();
}
}
//