示例#1
0
        /// <summary>
        /// Main place for drawing current fractal.
        /// Called when the first drawing is taking place, as well as all the next redraw.
        /// </summary>
        /// <param name="sender">Sender object - the picturebox on which the drawing will take place.</param>
        /// <param name="e">Some arguments.</param>
        private void DrawingPictureBox_Paint(object sender, PaintEventArgs e)
        {
            // Getting current drawing PictureBox object
            PictureBox drawingPictureBoxDesk = (PictureBox)sender;

            // Update current width and height of drawing panel.
            PictureBoxWidth  = drawingPictureBoxDesk.Width;
            PictureBoxHeight = drawingPictureBoxDesk.Height;

            // Update current bitmap.
            bitmap = new Bitmap(PictureBoxWidth, PictureBoxHeight);

            // Update graphics with new bitmap.
            DrawingPanel = Graphics.FromImage(bitmap);
            DrawingPanel.FillRectangle(new SolidBrush(Color.FromArgb(220, 220, 220)), new RectangleF(0, 0, PictureBoxWidth, PictureBoxHeight));

            DrawingPanel.InterpolationMode = InterpolationMode.HighQualityBicubic;
            DrawingPanel.ScaleTransform(Zoom, Zoom);

            if (DrawingPanel == null)
            {
                return;
            }
            try
            {
                fractal.Draw();
            }
            catch (NullReferenceException)
            {
                // It occurs when the user starts changing colors or changing the size of form and fractal need to redraw,
                // but there is no one current fractal, because user hasn't yet selected it from a list.
                // In this case, this behavior is considered correct, so nothing happens.
            }
            catch (TimeoutException)
            {
                // After throwing timeout error from fractal's drawing method.
                ClearAfterTimeoutExceeded();
            }
            catch { }

            e.Graphics.Clear(this.BackColor);
            e.Graphics.DrawImage(bitmap, 0, 0);
            base.OnPaint(e);
        }
示例#2
0
        /// <summary>
        /// OnPaint event for the left panel (a.k.a. canvas).
        /// </summary>
        private void FractalPaint(object sender, PaintEventArgs e)
        {
            if (_fractalCombobox.SelectedItem == null)
            {
                return;
            }

            var render = new Render(_scaleTextslider.Value, _cameraXOffsetTextslider.Value, _cameraYOffsetTextslider.Value, _canvasPanel.Size);

            Fractal fractal = _fractalCombobox.SelectedIndex switch
            {
                0 => new PythagoreanTree((int)_recursionTextslider.Value, _gradientColorA, _gradientColorB, render,
                                         _ptFirstLineLengthTextslider.Value, _ptLengthRatioTextslider.Value, _ptAngle1Textslider.Value, _ptAngle2Textslider.Value),
                1 => new KochCurve((int)_recursionTextslider.Value, _gradientColorA, _gradientColorB, render),
                2 => new SierpinskiCarpet((int)_recursionTextslider.Value, _gradientColorA, _gradientColorB, render),
                3 => new SierpinskiTriangle((int)_recursionTextslider.Value, _gradientColorA, _gradientColorB, render),
                4 => new CantorSet((int)_recursionTextslider.Value, _gradientColorA, _gradientColorB, render,
                                   _csVerticalDistanceTextslider.Value, _csHorizontalDistanceTextslider.Value, _csWidthTextslider.Value),
                _ => throw new NotImplementedException()
            };

            fractal.Draw(e.Graphics);
        }