Example #1
0
        public World(int width, int height, Rule rule)
        {
            int[,] seedRule = { {0,2,2,2,2,2,2,2,2,0,0,0,0,0,0},
                                {2,1,7,0,1,4,0,1,4,2,0,0,0,0,0},
                                {2,0,2,2,2,2,2,2,0,2,0,0,0,0,0},
                                {2,7,2,0,0,0,0,2,1,2,0,0,0,0,0},
                                {2,1,2,0,0,0,0,2,1,2,0,0,0,0,0},
                                {2,0,2,0,0,0,0,2,1,2,0,0,0,0,0},
                                {2,7,2,0,0,0,0,2,1,2,0,0,0,0,0},
                                {2,1,2,2,2,2,2,2,1,2,2,2,2,2,0},
                                {2,0,7,1,0,7,1,0,7,1,1,1,1,1,2},
                                {0,2,2,2,2,2,2,2,2,2,2,2,2,2,0} };
            this.height = height;
            this.width = width;
            grid = new Cell[width, height];

            //initialize cells
            for (int x = 0; x < width; x++)
                for (int y = 0; y < height; y++)
                    grid[x, y] = new Cell(this, Cell.CellState.Nothing, rule);

            // create initial loop
            int startX = width/2 - 7;
            int startY = height/2 - 5;
            for (int x = 0; x < 10; x++)
                for (int y = 0; y < 15; y++)
                {
                    grid[startX + x, startY + y].State = (Cell.CellState)seedRule[y, x];
                    Console.WriteLine('[' + x + ',' + y + ']');
                }
        }
Example #2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     bmp = new Bitmap(gridBox.Width, gridBox.Height);
     gpx = Graphics.FromImage(bmp);
     gridBox.Image = bmp;
     // Initialize the CA here.
     langtons = new LangtonsLoop.Rule();
     theCA = new World(gridBox.Width / DIVISOR, gridBox.Height / DIVISOR, langtons);
     updateGraphics();
     gridBox.Refresh();
     Console.WriteLine("The CA has been created.");
 }
Example #3
0
 public Cell(World world, CellState initialState, Rule rule)
 {
     this.world = world;
     this.currentState = initialState;
     this.rule = rule;
 }