/*This is an implementation of Conway's life in Java. Sieuwert van Otterloo 1998 sieuwert@bluering.nl www.bluering.nl/sieuwert This programs only original component is that it does not use a matrix for representing the world, but it keeps a list a cells that are alife. This is easier to program and also faster because most cells are dead. */ import java.applet.*; import java.awt.*; class cell { final static int lowerbound=1,upperbound=32567; //make sure upperbound <= 32567,lowerbound>0 public int x,y;//the coordinates of the cell public static int center()//the center of the universe of a cell //it's square, so just one int to return { return (lowerbound+upperbound)/2; } cell(int i,int j) { x=i; y=j; } public static boolean check(int x,int y) //is a cell (x,y) in the universe? { if(x=upperbound|| y=upperbound) return false; return true; } public long tolong() /*converts the cell to a long containing both x and y This 'zipping in' should make the program faster*/ { return x+32768*y; } public static int xfromlong(long l) //extracts an x-coordinate from a long { return (int)l%32768; } public static int yfromlong(long l) //extracts an y-coordinate from a long { return (int)l/32768; } } class world // a world represents the universe for one moment { static int maxcells=8000;//the maximum amount living cells cell[] celltable;//all living cells:the rest is dead int time,cells;//cells:number living cells. time:not used yet world(int t)//construct an empty world { time=t; celltable= new cell[maxcells]; cells=0; } public void empty()//kill all cells in this world { for(cells=cells;cells>0;cells--) celltable[cells-1]=null; time=0; } world(world former)//construct the world next to former { celltable= new cell[maxcells]; cells=0; time=former.time+1;//time is updated long[] buurtabel=new long[8*former.cells]; //buur means neighbour, tabel means array(or table). int buren=0; long place,eencel; for(int i=0;i0)//until the list is empty {eencel=buurtabel[0];//grab the first int aantal=0,index=0; while(buren>0&&index20) zoom=20; repaint(); } public void zoomout() {zoom--; if(zoom<2) zoom=2; repaint(); } public void update(Graphics g) { paint(g);}//avoids flickering public void paint(Graphics g) { int sx,sy; g.setColor(bgcolor); g.fillRect(0,0,300,300); g.setColor(textcolor); g.drawRect(0,0,299,299); g.setColor(cellkleur); for(int i=0;i