Wolfram Code for Cellular Automata / セル・オートマトンのウルフラム・コード

Aim / 目的

  1. Create a 1 dimensional cellular automata program to test Steven Wolfram's "Wolfram Code" using Basic Graphics.
    Basic Graphics を用いて1次元セルオートマトンを作成し、スティーブン・ウルフラムのウルフラム・コードの動作を検証する。

Getting ready / 準備

  1. Download Basic Graphics / Basic Graphicsライブラリのダウンロード
    basic.jar
  2. Edit file WolframCode.java / WolframCode.java を開く
    notepad GameOfLife.java

Step 1 / ステップ 1

  1. Create an 1 dimensional array to hold the current state of the 1 dimensional cellular automata.
    1次元セルオートマトンの状態を格納する1次元配列を生成。
    /* 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
    
  2. Save file WorlframCode.java / ファイル WolframCode.java を保存

  3. Compile and check / コンパイルして確認
    javac -cp basic.jar;. WolframCode.java
  4. Run and check / 実行して確認
    java -cp basic.jar;. WolframCode

Step 2 / ステップ 2

  1. Find the pattern of 3 adjacent cells.
    3つの連続するセルの状態パターンを計算する。
    Added source code in blue / 追加されたソースコードは青で表示
    /* 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
    
  2. Save file WorlframCode.java / ファイル WolframCode.java を保存

  3. Compile and check / コンパイルして確認
    javac -cp basic.jar;. WolframCode.java
  4. Run and check / 実行して確認
    java -cp basic.jar;. WolframCode

Step 3 / ステップ 3

  1. Lookup the rule for the adjacent pattern using the specified Wolfram Code.
    Set the value of the Wolfram Code rule to become the value of the cell in the next state.
    隣接パターンのルールを設定したウルフラム・コードから調べる。
    セルの次の状態は、ウルフラム・コードのルールに従い設定する。
    Added source code in blue / 追加されたソースコードは青で表示
    /* 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 class
    
    WolframCode.java

  2. Save file WorlframCode.java / ファイル WolframCode.java を保存

  3. Compile and check / コンパイルして確認
    javac -cp basic.jar;. WolframCode.java
  4. Run and check / 実行して確認
    java -cp basic.jar;. WolframCode

Random initial state / ランダム初期状態

Other Interesting Wolfram Codes / その他のウルフラム・コード

References / 参考資料

Basic Graphics
Tokyo University of Information Sciences, Department of Informatics 東京情報大学 総合情報学科
Ken Mackin マッキン ケネス