private void DoCellularAutomata(object sender, EventArgs e)
 {
     _cells = _cells.ApplyRules(_rules, _settings.NeighborhoodFunction );
     _settings.CellStructure.Painter.PaintBitmap(_bmp, _cells, _ptOffset, _colors);
     Invalidate();
 }
Example #2
0
        public Cells Clone()
        {
            Cells clone = new Cells(_cellStruct);
            clone._ary = (int[,])_ary.Clone();

            return clone;
        }
Example #3
0
        public override IEnumerable<int> Neighbors(Cells cells, int col, int row)
        {
            bool isRightSideUp = (col + row) % 2 == 0;
            if (isRightSideUp)
            {
                yield return cells[cells.WrapColumn(col - 1), cells.WrapRow(row -1)];
                yield return cells[cells.WrapColumn(col), cells.WrapRow(row -1)];
                yield return cells[cells.WrapColumn(col + 1), cells.WrapRow(row - 1)];

                yield return cells[cells.WrapColumn(col - 2), cells.WrapRow(row + 1)];
                yield return cells[cells.WrapColumn(col - 2), row];
                yield return cells[cells.WrapColumn(col - 1), row];

                yield return cells[cells.WrapColumn(col - 1), cells.WrapRow(row + 1)];
                yield return cells[cells.WrapColumn(col), cells.WrapRow(row + 1)];
                yield return cells[cells.WrapColumn(col + 1), cells.WrapRow(row + 1)];

                yield return cells[cells.WrapColumn(col + 2), cells.WrapRow(row + 1)];
                yield return cells[cells.WrapColumn(col + 2), row];
                yield return cells[cells.WrapColumn(col + 1), row];
            }
            else
            {
                yield return cells[cells.WrapColumn(col - 1), cells.WrapRow(row + 1)];
                yield return cells[cells.WrapColumn(col), cells.WrapRow(row + 1)];
                yield return cells[cells.WrapColumn(col + 1), cells.WrapRow(row + 1)];

                yield return cells[cells.WrapColumn(col - 2), cells.WrapRow(row - 1)];
                yield return cells[cells.WrapColumn(col - 2), row];
                yield return cells[cells.WrapColumn(col - 1), row];

                yield return cells[cells.WrapColumn(col - 1), cells.WrapRow(row - 1)];
                yield return cells[cells.WrapColumn(col), cells.WrapRow(row - 1)];
                yield return cells[cells.WrapColumn(col + 1), cells.WrapRow(row - 1)];

                yield return cells[cells.WrapColumn(col + 2), cells.WrapRow(row - 1)];
                yield return cells[cells.WrapColumn(col + 2), row];
                yield return cells[cells.WrapColumn(col + 1), row];
            }
        }
 public void Run(Cells cells, CellularAutomataRules rules)
 {
     _cells = cells;
     _ptOffset = CalculateOffset();
     Rules = (rules != null) ? rules : _rules;
     _timer.Start();
 }
Example #5
0
 public override IndexPair GetColRowFromXy(Cells cells, int x, int y)
 {
     float fX = x;
     float fY = y;
     float fColumn = (fX + (float)TriangleCellPainter.HALF_WD) / (float)TriangleCellPainter.HALF_WD_CEIL;
     float fRow = fY / (float)TriangleCellPainter.CELL_HGT;
     return new IndexPair(
         cells.WrapColumn((int)Math.Round(fColumn)),
         cells.WrapRow((int)Math.Round(fRow))
     );
 }
Example #6
0
 public override Point GetXyCoordinates(Cells cells, int col, int row)
 {
     int x = col * TriangleCellPainter.HALF_WD_CEIL - TriangleCellPainter.HALF_WD;
     int y = row * TriangleCellPainter.CELL_HGT;
     return new Point(x, y);
 }
Example #7
0
 public override Point GetXyCoordinates(Cells cells, int col, int row)
 {
     return new Point(2*col, 2*row);
 }
Example #8
0
 public override IEnumerable<int> Neighbors(Cells cells, int col, int row)
 {
     yield return cells[col, cells.WrapRow(row - 1)];
     yield return cells[cells.WrapColumn(col + 1), row];
     yield return cells[col, cells.WrapRow(row + 1)];
     yield return cells[cells.WrapColumn(col - 1), row];
 }
Example #9
0
        public override IndexPair GetColRowFromXy(Cells cells, int x, int y)
        {
            int row = y / 2;
            int col = x / 2;

            if (col < 0)
                col += cells.Columns;
            else if (col >= cells.Columns)
                col -= cells.Columns;

            if (row < 0)
                row += cells.Rows;
            else if (row >= cells.Rows)
                row -= cells.Rows;

            return new IndexPair(col, row);
        }
Example #10
0
        public override Point GetXyCoordinates(Cells cells, int col, int row)
        {
            int x = (col * 2 + row ) % (cells.Columns * 2);
            int y = row * 2;

            return new Point(x, y);
        }
Example #11
0
 public abstract IEnumerable<int> Neighbors(Cells cells, int col, int row);
Example #12
0
 public abstract Point GetXyCoordinates(Cells cells, int col, int row);
Example #13
0
 public abstract IndexPair GetColRowFromXy(Cells cells, int col, int row);