/// <summary> /// The constructor. /// </summary> public UniverseDisplayCell(int paneWidth, int paneHeight, Label label) { int width = paneWidth / Settings.Default.Zoom; int height = paneHeight / Settings.Default.Zoom; _label = label; var universe = new UniverseHolder(height, width, 3); var physics = new MergePhysics(universe); universe.Randomize(_rnd); physics.Randomize(); _universeRunner = new UniverseRunner(universe, physics); _visualizer = new UniverseVisualizer(universe, Settings.Default.Zoom); _bitmap = new WriteableBitmap( paneWidth, paneHeight, 96, 96, PixelFormats.Bgr32, null); }
/// <inheritdoc /> public void ProcessPixel(UniverseHolder outputUniverse, int row, int col) { double total = 0; int cnt = 0; for (int dir = 0; dir < _rowTransform.Length; dir++) { int otherRow = row + _rowTransform[dir]; int otherCol = col + _colTransform[dir]; if (_universe.IsValid(otherRow, otherCol)) { UniverseCell otherCell = _universe.Get(otherRow, otherCol); total += otherCell.Avg; cnt++; } } total /= cnt; for (int i = 0; i < _colorTable.Length; i++) { int idx = _dataOrder[i]; if (total < _data[idx * 2]) { for (int j = 0; j < outputUniverse.CellSize; j++) { double d = _colorTable[idx][j] - _universe.Get(row, col).Data[j]; double pct = _data[1 + idx * 2]; pct = (pct + 1.0) / 2.0; d *= pct; outputUniverse.Add(row, col, j, d); } break; } } }
/// <summary> /// Construct the merge physics. /// </summary> /// <param name="theUniverse">The universe.</param> public MergePhysics(UniverseHolder theUniverse) { _data = new double[2 * _colorTable.Length]; _dataOrder = new int[_colorTable.Length]; _universe = theUniverse; }