Пример #1
0
        public override void RenderStep(MazeGenerationResults results)
        {
            Polygons = new List <ColoredPolygon>();
            base.RenderStep(results);
            var allPoints         = Polygons.SelectMany(x => x.Points).ToArray();
            var commonPolygon     = new Polygon(allPoints);
            var boundingRectangle = commonPolygon.GetBoundingRectangle();
            var bmp      = new Bitmap(boundingRectangle.Width, boundingRectangle.Height);
            var graphics = Graphics.FromImage(bmp);

            foreach (var polygon in Polygons)
            {
                var adjustedPoints = polygon.Points.Select(x => new System.Drawing.Point(x.X - boundingRectangle.X, x.Y - boundingRectangle.Y)).ToArray();
                graphics.FillPolygon(Brushes[polygon.Color], adjustedPoints);
            }

            GifImage.AddFrame(bmp, FrameDelay, boundingRectangle.X, boundingRectangle.Y);
            if (results.ResultsType == GenerationResultsType.GenerationCompleted)
            {
                GifImage.Complete();
                GifImage.OutStream.Position = 0;
                using (var fs = new FileStream(FilePath, FileMode.Create))
                {
                    GifImage.OutStream.CopyTo(fs);
                }
            }
        }