예제 #1
0
 private void DoCellularAutomata(object sender, EventArgs e)
 {
     _cells = _cells.ApplyRules(_rules, _settings.NeighborhoodFunction );
     _settings.CellStructure.Painter.PaintBitmap(_bmp, _cells, _ptOffset, _colors);
     Invalidate();
 }
예제 #2
0
파일: Cells.cs 프로젝트: jwezorek/Lifelike
        public Cells Clone()
        {
            Cells clone = new Cells(_cellStruct);
            clone._ary = (int[,])_ary.Clone();

            return clone;
        }
예제 #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];
            }
        }
예제 #4
0
 public void Run(Cells cells, CellularAutomataRules rules)
 {
     _cells = cells;
     _ptOffset = CalculateOffset();
     Rules = (rules != null) ? rules : _rules;
     _timer.Start();
 }
예제 #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))
     );
 }
예제 #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);
 }
예제 #7
0
 public override Point GetXyCoordinates(Cells cells, int col, int row)
 {
     return new Point(2*col, 2*row);
 }
예제 #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];
 }
예제 #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);
        }
예제 #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);
        }
예제 #11
0
 public abstract IEnumerable<int> Neighbors(Cells cells, int col, int row);
예제 #12
0
 public abstract Point GetXyCoordinates(Cells cells, int col, int row);
예제 #13
0
 public abstract IndexPair GetColRowFromXy(Cells cells, int col, int row);