예제 #1
0
파일: DragonPainter.cs 프로젝트: pa1ch/di
 public void    Paint()
 {
     using    (var graphics = imageHolder.StartDrawing())
     {
         graphics.FillRectangle(Brushes.Black, 0, 0, imageSize.Width, imageSize.Height);
         var r      = new    Random();
         var cosa   = (float)Math.Cos(settings.Angle1);
         var sina   = (float)Math.Sin(settings.Angle1);
         var cosb   = (float)Math.Cos(settings.Angle2);
         var sinb   = (float)Math.Sin(settings.Angle2);
         var shiftX = settings.ShiftX * size * 0.8f;
         var shiftY = settings.ShiftY * size * 0.8f;
         var scale  = settings.Scale;
         var p      = new    PointF(0, 0);
         foreach (var i    in    Enumerable.Range(0, settings.IterationsCount))
         {
             graphics.FillRectangle(Brushes.Yellow, imageSize.Width / 3f + p.X, imageSize.Height / 2f + p.Y, 1, 1);
             if (r.Next(0, 2) == 0)
             {
                 p = new    PointF(scale * (p.X * cosa - p.Y * sina), scale * (p.X * sina + p.Y * cosa));
             }
             else
             {
                 p = new    PointF(scale * (p.X * cosb - p.Y * sinb) + shiftX, scale * (p.X * sinb + p.Y * cosb) + shiftY);
             }
             if (i % 100 == 0)
             {
                 imageHolder.UpdateUi();
             }
         }
     }
     imageHolder.UpdateUi();
 }
예제 #2
0
 public void Paint()
 {
     using (var graphics = imageHolder.StartDrawing())
     {
         var imageSize = imageHolder.GetImageSize();
         var size      = Math.Min(imageSize.Width, imageSize.Height) / 2.1f;
         graphics.FillRectangle(new SolidBrush(palette.BackgroundColor), 0, 0, imageSize.Width, imageSize.Height);
         DrawDragon(size, graphics, imageSize);
     }
     imageHolder.UpdateUi();
 }
예제 #3
0
파일: Painter.cs 프로젝트: elizShtol/fp
        public Result <Graphics> PaintTags()
        {
            var tags = tagCreator.GetTagsForVisualization();
            var startDrawingResult = imageHolder.StartDrawing();

            if (!startDrawingResult.IsSuccess)
            {
                return(startDrawingResult);
            }
            using (var graphics = startDrawingResult.Value)
            {
                graphics.Clear(colorSettingsProvider.ColorSettings.BackgroundColor);
                var result = new Result <Graphics>(null, graphics);
                foreach (var tag in tags)
                {
                    result = PaintTag(tag, graphics);
                    if (!result.IsSuccess)
                    {
                        return(result);
                    }
                }

                imageHolder.UpdateUi();
                return(result);
            }
        }
예제 #4
0
        public void Paint()
        {
            var rng           = new Random();
            var shuffledWords = settings.Ordered
                ? words.OrderByDescending(x => x.Value)
                : words.OrderBy(a => rng.Next());

            using (var graphics = imageHolder.StartDrawing())
                using (var backgroundBrush = new SolidBrush(palette.SecondaryColor))
                    using (var rectPen = new Pen(palette.PrimaryColor))
                        using (var textBrush = new SolidBrush(palette.PrimaryColor))
                            using (var backgroundPictureBrush = new SolidBrush(palette.BackgroundColor))
                            {
                                Result
                                .OfAction(() => graphics.FillRectangle(backgroundPictureBrush, 0, 0, imageSize.Width,
                                                                       imageSize.Height))
                                .OnError(err => MessageBox.Show(err));
                                foreach (var word in shuffledWords)
                                {
                                    Result
                                    .OfAction(() =>
                                              DrawRectangle(graphics, word.Key, word.Value, backgroundBrush, rectPen, textBrush))
                                    .OnError(err => MessageBox.Show(err));
                                }
                            }

            imageHolder.UpdateUi();
        }
예제 #5
0
        public void CloudPainter_ShouldCallUpdate_OnlyOnce()
        {
            var painter = new CloudPainter(imageHolder, settings, palette, layouter);

            painter.Paint();

            A.CallTo(() => imageHolder.UpdateUi()).WithAnyArguments().MustHaveHappenedOnceExactly();
        }
예제 #6
0
        public void Paint()
        {
            var imageSize = imageHolder.GetImageSize();
            var size      = Math.Min(imageSize.Width, imageSize.Height) / 2.1f;

            using (var graphics = imageHolder.StartDrawing())
            {
                graphics.FillRectangle(
                    new SolidBrush(palette.BackgroundColor),
                    0, 0,
                    imageSize.Width, imageSize.Height);

                var r = new Random();

                var cosa = (float)Math.Cos(settings.Angle1);
                var sina = (float)Math.Sin(settings.Angle1);
                var cosb = (float)Math.Cos(settings.Angle2);
                var sinb = (float)Math.Sin(settings.Angle2);

                var shiftX = settings.ShiftX * size * 0.8f;
                var shiftY = settings.ShiftY * size * 0.8f;
                var scale  = settings.Scale;

                var p = new PointF(0, 0);

                foreach (var i in Enumerable.Range(0, settings.IterationsCount))
                {
                    graphics.FillRectangle(
                        new SolidBrush(palette.PrimaryColor),
                        imageSize.Width / 3f + p.X, imageSize.Height / 2f + p.Y,
                        1, 1);

                    p = r.Next(0, 2) == 0
                        ? new PointF(scale * (p.X * cosa - p.Y * sina), scale * (p.X * sina + p.Y * cosa))
                        : new PointF(scale * (p.X * cosb - p.Y * sinb) + shiftX, scale * (p.X * sinb + p.Y * cosb) + shiftY);

                    if (i % 100 == 0)
                    {
                        imageHolder.UpdateUi();
                    }
                }
            }

            imageHolder.UpdateUi();
        }
예제 #7
0
파일: KochPainter.cs 프로젝트: pa1ch/di
 public void    Paint()
 {
     using    (var graphics = imageHolder.StartDrawing())
     {
         graphics.FillRectangle(new    SolidBrush(palette.BackgroundColor), 0, 0, imageSize.Width, imageSize.Height);
         DrawSegment(graphics, 0, imageSize.Height * 0.9f, imageSize.Width, imageSize.Height * 0.9f, true);
     }
     imageHolder.UpdateUi();
 }
예제 #8
0
        public void CloudPainter_ShouldCallUpdate_OnlyOnce()
        {
            var words = new Dictionary <string, int> {
                ["hello"] = 1
            };
            var painter = new CloudWithWordsPainter(imageHolder, settings, palette, layouter, words);

            painter.Paint();

            A.CallTo(() => imageHolder.UpdateUi()).WithAnyArguments().MustHaveHappenedOnceExactly();
        }
예제 #9
0
 public void Paint()
 {
     using (var graphics = imageHolder.StartDrawing())
         using (var backgroundBrush = new SolidBrush(palette.SecondaryColor))
             using (var rectBrush = new Pen(palette.PrimaryColor))
                 using (var backgroundPictureBrush = new SolidBrush(palette.BackgroundColor))
                 {
                     Result
                     .OfAction(() =>
                               graphics.FillRectangle(backgroundPictureBrush, 0, 0, imageSize.Width, imageSize.Height))
                     .OnError(err => MessageBox.Show(err));
                     for (var i = 0; i < settings.IterationsCount; i++)
                     {
                         Result
                         .Of(() => GetRandomSize(settings))
                         .Then(x => layouter.PutNextRectangle(x))
                         .Then(x => DrawRectangle(graphics, backgroundBrush, rectBrush, x))
                         .OnError(err => MessageBox.Show(err));
                     }
                 }
     imageHolder.UpdateUi();
 }