예제 #1
0
 public void Paint()
 {
     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);
         var pointBrush = new SolidBrush(palette.PrimaryColor);
         foreach (var i in Enumerable.Range(0, settings.IterationsCount))
         {
             graphics.FillRectangle(pointBrush, 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
파일: 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);
            }
        }
예제 #3
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();
        }
예제 #4
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();
 }
예제 #5
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();
 }
예제 #6
0
        public void CloudPainter_ShouldCallStartDrawing_OnlyOnce()
        {
            var words = new Dictionary <string, int> {
                ["hello"] = 1
            };
            var painter = new CloudWithWordsPainter(imageHolder, settings, palette, layouter, words);

            painter.Paint();

            A.CallTo(() => imageHolder.StartDrawing()).WithAnyArguments().MustHaveHappenedOnceExactly();
        }
예제 #7
0
 public void SetUp()
 {
     imageHolder = A.Fake <IImageHolder>();
     settings    = A.Fake <ICircularCloudLayouterWithWordsSettings>();
     palette     = A.Fake <IPalette>();
     layouter    = A.Fake <ICircularCloudLayouter>();
     graphics    = A.Fake <IGraphicDrawer>();
     A.CallTo(() => imageHolder.GetImageSize()).Returns(new Size(600, 600));
     A.CallTo(() => imageHolder.StartDrawing()).Returns(graphics);
     A.CallTo(() => settings.CenterX).Returns(300);
     A.CallTo(() => settings.Scale).Returns(5);
     A.CallTo(() => settings.CenterY).Returns(300);
     A.CallTo(() => palette.PrimaryColor).Returns(Color.Black);
     A.CallTo(() => palette.BackgroundColor).Returns(Color.Black);
     A.CallTo(() => palette.SecondaryColor).Returns(Color.Black);
 }
예제 #8
0
        public Result <None> Paint(IEnumerable <Word> words)
        {
            var imageSize = imageSettings.ImageSize;

            imageHolder.RecreateImage(imageSize);
            var graphics = imageHolder.StartDrawing();

            return(Result
                   .Of(() => words.Select(x => ValidateDrawingWord(x, imageSize)))
                   .Then(wordsToDraw =>
            {
                foreach (var word in wordsToDraw)
                {
                    graphics.DrawString(word.Text, word.Font, new SolidBrush(imageSettings.GetColor()),
                                        word.Rectangle.Location);
                }
            }));
        }
예제 #9
0
 public void SetUp()
 {
     imageHolder = A.Fake <IImageHolder>();
     settings    = A.Fake <ICircularCloudLayouterSettings>();
     palette     = A.Fake <IPalette>();
     layouter    = A.Fake <ICircularCloudLayouter>();
     graphics    = A.Fake <IGraphicDrawer>();
     A.CallTo(() => imageHolder.GetImageSize()).Returns(new Size(600, 600));
     A.CallTo(() => imageHolder.StartDrawing()).Returns(graphics);
     A.CallTo(() => settings.MinSize).Returns(10);
     A.CallTo(() => settings.MaxSize).Returns(30);
     A.CallTo(() => settings.CenterX).Returns(300);
     A.CallTo(() => settings.CenterY).Returns(300);
     A.CallTo(() => settings.IterationsCount).Returns(5);
     A.CallTo(() => settings.XCompression).Returns(1);
     A.CallTo(() => settings.YCompression).Returns(1);
     A.CallTo(() => palette.PrimaryColor).Returns(Color.Black);
     A.CallTo(() => palette.BackgroundColor).Returns(Color.Black);
     A.CallTo(() => palette.SecondaryColor).Returns(Color.Black);
 }
예제 #10
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();
 }