示例#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
 private void DoCellularAutomata(object sender, EventArgs e)
 {
     _cells = _cells.ApplyRules(_rules, _settings.NeighborhoodFunction);
     _settings.CellStructure.Painter.PaintBitmap(_bmp, _cells, _ptOffset, _colors);
     Invalidate();
 }