private void ExportAsAnimatedGifWorker(string outputFilePath, ProgressBox box, int numFramesPreamble, int numFrames) { Cells cells = _genAlg.CaSettings.GetInitialCells(_genAlg.GaSettings.InitialStateDistribution); CellularAutomataRules rules = ctrlCellularAutomata.Rules; NeighborhoodFunction function = _genAlg.CaSettings.NeighborhoodFunction; CellPainter painter = _genAlg.CaSettings.CellStructure.Painter; for (int i = 0; i < numFramesPreamble; i++) { cells = cells.ApplyRules(rules, function); box.Invoke( new Action( () => box.Increment() ) ); } using (FileStream fs = new FileStream(outputFilePath, FileMode.Create)) using (GifEncoder encoder = new GifEncoder(fs, cells.Columns * 2, cells.Rows * 2)) { Bitmap bmp = new Bitmap(cells.Columns * 2, cells.Rows * 2); Point offset = new Point(0, 0); for (int i = 0; i < numFrames; i++) { painter.PaintBitmap(bmp, cells, offset, ctrlCellularAutomata.Colors); encoder.AddFrame(Image.FromHbitmap(bmp.GetHbitmap()), 0, 0, new TimeSpan(0)); cells = cells.ApplyRules(rules, function); box.Increment(); } } box.Finish(); }
public Cells ApplyRules(CellularAutomataRules rules, NeighborhoodFunction func) { Cells cells = (Cells) this.Clone(); for (int row = 0; row < Rows; row++) for (int col = 0; col < Columns; col++) cells[col, row] = rules.GetSuccessorState(this[col, row], func.Map(this.Neighbors(col, row), rules.NumStates)); return cells; }
public void Set(string nameCellStructure, int numStates, string nameNeighborhoodFunc) { _settings.NumStates = numStates; _settings.CellStructure = CellStructure.Get(nameCellStructure); _settings.NeighborhoodFunction = NeighborhoodFunction.Get(nameNeighborhoodFunc); UpdateUi(); }
public Cells ApplyRules(CellularAutomataRules rules, NeighborhoodFunction func) { Cells cells = (Cells)this.Clone(); for (int row = 0; row < Rows; row++) { for (int col = 0; col < Columns; col++) { cells[col, row] = rules.GetSuccessorState(this[col, row], func.Map(this.Neighbors(col, row), rules.NumStates)); } } return(cells); }
public CellularAutomataRules GetRandomRules(DiscreteProbabilityDistribution <int> stateTableDistribution) { return(new CellularAutomataRules( NeighborhoodFunction.GetRange(NeighborsCount, NumStates), NumStates, stateTableDistribution)); }
public CellularAutomataSettings(int states) { _numStates = states; _cellStructure = new HexSixCell(); _funcMapNeighbors = new AliveCellCount(); }
private void comboMappingFunction_SelectedIndexChanged(object sender, EventArgs e) { _settings.NeighborhoodFunction = NeighborhoodFunction.Get(comboMappingFunction.SelectedIndex); OnChanged(); }