package ca; import java.awt.Image; import java.awt.Graphics; import java.awt.Component; import java.awt.Dimension; import java.awt.image.*; import java.util.*; public abstract class CAs implements Runnable { //private Graphics paper; public Image bufImage; public Graphics backPaper; public short cellWidth = 2; public short cellHeight = 2; public int width = 0; public int height = 0; public boolean wrap = true; protected short cells[][]; protected short cells2[][]; protected static short STATE = 2; public short table[][]; // table protected Component target; protected static final boolean DEBUG = false; int black = 0xff000000; int yellow = 0xffffff00; int blue = 0xff0000ff; public int cols[] = {black,blue}; protected int[] p; public CAs(){} public void setWrap(boolean wrap){ this.wrap = wrap; } public boolean getWrap(){ return wrap; } public short getCellStatus( int x, int y){ if( x >= 0 && x/cellWidth < cells.length && y >= 0 && y/cellHeight < cells[x].length){ return cells[x/cellWidth][y/cellHeight]; } return -1; } public void setCellStatus(int x, int y, short value){ if( x >= 0 && x/cellWidth < cells.length && y >= 0 && y/cellHeight < cells[x].length){ cells[x/cellWidth][(y/cellHeight)] = (short)(value % STATE); } } public void setCells ( short[][] data){ cells = data; cells2 = new short[data.length][data[0].length]; Clear(cells2); } public void setTarget(Component target){ this.target = target; //this.paper = paper; //this.bufImage = bufImage; //this.backPaper = bufImage.getGraphics(); Dimension r = target.size(); width = r.width/cellWidth; height = r.height/cellHeight; cells = new short[width][height]; Randmize(cells); cells2 = new short[width][height]; Clear(cells2); p = new int [width * height]; for(int i = 0;i