notepad GameOfLife.java
/* Wolfram Code */ import jp.ac.tuis.basic.*; public class WolframCode{ public static void main(String[] args){ BasicGraphics g = new BasicGraphics(100, 40, 10); //start graphics int[] cell = new int[1000]; //width of 1 line of cells cell[cell.length/2]=1; //set center of cells to 1 for(int y=0; y<500; y++){ //calculate 1 line at a time //draw 1 line for(int x=0; x<cell.length; x++){ g.color(g.WHITE); if(cell[x]==1) g.pset(x,y); //draw a dot for 1 } g.sleep(100); //slow down graphics animation }//end for y }//end main }//end class
javac -cp basic.jar;. WolframCode.java
java -cp basic.jar;. WolframCode
/* Wolfram Code */
import jp.ac.tuis.basic.*;
public class WolframCode{
public static void main(String[] args){
BasicGraphics g = new BasicGraphics(100, 40, 10); //start graphics
int[] cell = new int[1000]; //width of 1 line of cells
cell[cell.length/2]=1; //set center of cells to 1
for(int y=0; y<500; y++){ //calculate 1 line at a time
//draw 1 line
for(int x=0; x<cell.length; x++){
g.color(g.WHITE);
if(cell[x]==1) g.pset(x,y); //draw a dot for 1
}
//find a pattern of 3 adjacent cells
for(int x=1; x<cell.length-1; x++){
int pattern = 0;
if(cell[x+1]==1) pattern+=1; //binary calculation
if(cell[x]==1) pattern+=2;
if(cell[x-1]==1) pattern+=4;
}
g.sleep(100); //slow down graphics animation
}//end for y
}//end main
}//end class
javac -cp basic.jar;. WolframCode.java
java -cp basic.jar;. WolframCode
/* Wolfram Code */ import jp.ac.tuis.basic.*; public class WolframCode{ public static void main(String[] args){ BasicGraphics g = new BasicGraphics(100, 40, 10); //start graphics int[] cell = new int[1000]; //width of 1 line of cells int[] newcell = new int[cell.length]; //new line of cells int[] rule = new int[8]; //rule binary string //rule 90 in binary is 01011010 rule[7]=0; rule[6]=1; rule[5]=0; rule[4]=1; rule[3]=1; rule[2]=0; rule[1]=1; rule[0]=0; cell[cell.length/2]=1; //set center of cells to 1 for(int y=0; y<500; y++){ //calculate 1 line at a time //draw 1 line for(int x=0; x<cell.length; x++){ g.color(g.WHITE); if(cell[x]==1) g.pset(x,y); //draw a dot for 1 } //find a pattern of 3 adjacent cells for(int x=1; x<cell.length-1; x++){ int pattern = 0; if(cell[x+1]==1) pattern+=1; //binary calculation if(cell[x]==1) pattern+=2; if(cell[x-1]==1) pattern+=4; newcell[x]=rule[pattern]; //look up rule string } //copy new line of cells to original cells for(int x=1; x<cell.length-1; x++){ cell[x]=newcell[x]; //copy to cell newcell[x]=0; //and reset } g.sleep(100); //slow down graphics animation }//end for y }//end main }//end classWolframCode.java
javac -cp basic.jar;. WolframCode.java
java -cp basic.jar;. WolframCode
/* Wolfram Code */
import jp.ac.tuis.basic.*;
public class WolframCode{
public static void main(String[] args){
BasicGraphics g = new BasicGraphics(100, 40, 10); //start graphics
int[] cell = new int[1000]; //width of 1 line of cells
int[] newcell = new int[cell.length]; //new line of cells
int[] rule = new int[8]; //rule binary string
//rule 90 in binary is 01011010
rule[7]=0;
rule[6]=1;
rule[5]=0;
rule[4]=1;
rule[3]=1;
rule[2]=0;
rule[1]=1;
rule[0]=0;
//cell[cell.length/2]=1; //set center of cells to 1
for(int x=1; x<cell.length-1; x++) cell[x]=Math.random()<0.1 ? 1 : 0; //random initial state
for(int y=0; y<500; y++){ //calculate 1 line at a time
//draw 1 line
for(int x=0; x<cell.length; x++){
g.color(g.WHITE);
if(cell[x]==1) g.pset(x,y); //draw a dot for 1
}
//find a pattern of 3 adjacent cells
for(int x=1; x<cell.length-1; x++){
int pattern = 0;
if(cell[x+1]==1) pattern+=1; //binary calculation
if(cell[x]==1) pattern+=2;
if(cell[x-1]==1) pattern+=4;
newcell[x]=rule[pattern]; //look up rule string
}
//copy new line of cells to original cells
for(int x=1; x<cell.length-1; x++){
cell[x]=newcell[x]; //copy to cell
newcell[x]=0; //and reset
}
g.sleep(100); //slow down graphics animation
}//end for y
}//end main
}//end class