// Wormz.java - from members.aol.com/wmjbkr's drawbots2 import java.applet.Applet; import java.awt.*; import java.util.Vector; public class Wormz extends Applet implements Runnable { public void start () { if (_thr == null) {_thr = new Thread (this); _thr.start ();} } public void stop () { if (_thr != null) {_thr.stop (); _thr = null;} } public void run () { long l = System.currentTimeMillis (); _thr.setPriority (1); while (_thr != null) { try { l += 2; Thread.sleep (Math.max (0L, l - System.currentTimeMillis ())); } catch (InterruptedException interruptedexception) {} repaint (); } } public Wormz () { _thr = null; _nPal = 4096; _bg = new Color (7, 7, 7); _nWormz = 0; _wormz = new Vector (10, 1); } public void init () { _w = size ().width; _h = size ().height; setBackground (_bg); _pal = new Color [_nPal]; float f = 0.0F; float f1 = (float)(1.0D / (double)_nPal); for (int i = 0; i < _nPal; i++) {_pal [i] = Color.getHSBColor (f, 1.0F, 1.0F); f += f1;} _pxlGot = new boolean [_w * _h]; for (int j = 0; j < _w * _h; j++) _pxlGot [j] = false; } public void paint (Graphics g) { for (int l = 0; l < _nWormz; l++) { _curWorm = (Worm) _wormz.elementAt (l); _curWormNum = l; int l1 = _curWorm._color; if (_curWorm._growing) g.setColor (_pal [l1]); else g.setColor (Color.black); for (int i2 = 0; i2 < _curWorm._nPxlDraw; i2++) { int j2 = _curWorm._pxlDraw [i2].x; int k2 = _curWorm._pxlDraw [i2].y; g.drawLine (j2, k2, j2, k2); } if (_curWorm._died) {_wormz.removeElement (_curWorm); _nWormz--;} else {_curWorm.next ();} } } public void update (Graphics g) {paint (g);} public boolean mouseDown (Event event, int x, int y) { _tstWorm = new Worm (x, y, this); if (_tstWorm.canAdd (x, y, _tstWorm._growDir)) {_wormz.addElement (_tstWorm); _nWormz++; return true;} else {_tstWorm = null; return false;} } Thread _thr; int _w, _h, _nPal, _nWormz, _curWormNum; Color _pal [], _bg; Worm _tstWorm, _curWorm; Vector _wormz; boolean _pxlGot []; }