import java.awt.*;/************************************ Applet zur Simulation des Life ** Algorithmus ***********************************/public class LifeApplet extends java.applet.Applet { boolean ende = false; public void paint(Graphics g) { Color color1=new Color(0,175,0); Color color2=new Color(0,0,0); int xmin = 0; int ymin = 0; int xmax = 0; int ymax = 0; //Zuweisen der Parameter aus der HTML Datei xmax = Integer.parseInt(this.getParameter("xm")); ymax = Integer.parseInt(this.getParameter("ym")); int xl, xr, yu, yo, hvalue; int field[][] = new int[xmax] [ymax]; int hfield[][] = new int [xmax] [ymax]; //Füllen der Felder mit den Werten for (int x=0;x<xmax;x++) { for (int y=0;y<ymax;y++) { field[x][y] = (int) (Math.random()*2); } } while(ende == false) { //Bildschirmausgabe for (int x=0;x<xmax;x++) { for (int y=0;y<ymax;y++) { //int valueR = (int) (Math.random() * 255); //int valueG = (int) (Math.random() * 255); //int valueB = (int) (Math.random() * 255); if (field[x][y]==1) g.setColor(color1); else g.setColor(color2); g.drawLine(x, y, x, y); //Berechnung der neuen Werte if(x==xmin) xl=xmax-1; else xl=x-1; if(x==xmax-1) xr=xmin; else xr=x+1; if(y==ymin) yo=ymax-1; else yo=y-1; if(y==ymax-1) yu=ymin; else yu=y+1; hvalue=field[xl][yo]+field[x][yo]+field[xr][yo]+field[xr][y]+field[xr][yu]+field[x][yu]+field[xl][yu]+field[xl][y]; if(hvalue==3 || (hvalue==2 && field[x][y]!=0)) hfield[x][y]=1; else hfield[x][y]=0; } } for (int x=0;x<xmax;x++) { for (int y=0;y<ymax;y++) { field[x][y]=hfield[x][y]; } } } } public void destroy() { ende = true; getGraphics().dispose(); System.exit(0); }}