private void DoCellularAutomata(object sender, EventArgs e) { _cells = _cells.ApplyRules(_rules, _settings.NeighborhoodFunction ); _settings.CellStructure.Painter.PaintBitmap(_bmp, _cells, _ptOffset, _colors); Invalidate(); }
public Cells Clone() { Cells clone = new Cells(_cellStruct); clone._ary = (int[,])_ary.Clone(); return clone; }
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(); }
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)) ); }
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); }
public override Point GetXyCoordinates(Cells cells, int col, int row) { return new Point(2*col, 2*row); }
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]; }
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); }
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); }
public abstract IEnumerable<int> Neighbors(Cells cells, int col, int row);
public abstract Point GetXyCoordinates(Cells cells, int col, int row);
public abstract IndexPair GetColRowFromXy(Cells cells, int col, int row);