コード例 #1
0
        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();
        }
コード例 #2
0
ファイル: Cells.cs プロジェクト: jwezorek/Lifelike
 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;
 }
コード例 #3
0
        public void Set(string nameCellStructure, int numStates, string nameNeighborhoodFunc)
        {
            _settings.NumStates            = numStates;
            _settings.CellStructure        = CellStructure.Get(nameCellStructure);
            _settings.NeighborhoodFunction = NeighborhoodFunction.Get(nameNeighborhoodFunc);

            UpdateUi();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public CellularAutomataRules GetRandomRules(DiscreteProbabilityDistribution <int> stateTableDistribution)
 {
     return(new CellularAutomataRules(
                NeighborhoodFunction.GetRange(NeighborsCount, NumStates),
                NumStates, stateTableDistribution));
 }
コード例 #6
0
 public CellularAutomataSettings(int states)
 {
     _numStates        = states;
     _cellStructure    = new HexSixCell();
     _funcMapNeighbors = new AliveCellCount();
 }
コード例 #7
0
 private void comboMappingFunction_SelectedIndexChanged(object sender, EventArgs e)
 {
     _settings.NeighborhoodFunction = NeighborhoodFunction.Get(comboMappingFunction.SelectedIndex);
     OnChanged();
 }