Esempio n. 1
0
        /// <summary>
        /// Render fractal.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox_Paint(object sender, PaintEventArgs e)
        {
            // Update fractal.
            fractal.X = x;
            fractal.Y = y;
            if (fractal is DragonsCurve)
            {
                DragonsCurve dc = fractal as DragonsCurve;
                dc.lastX = x + length * scale / 2;
                dc.lastY = y + length * scale / 2;
            }
            fractal.Length = length * scale;

            // Prepare for rendering.
            Graphics g          = e.Graphics;
            Pen      background = new Pen(Color.FromArgb(35, 35, 35));

            g.FillRectangle(background.Brush, new Rectangle(0, 0, pictureBox.Width, pictureBox.Height));

            // Update color buttons.
            colorButton1.FlatAppearance.BorderColor = Fractal.startColor;
            colorButton2.FlatAppearance.BorderColor = Fractal.endColor;

            // Render fractal.
            try
            {
                fractal.Render(e.Graphics);
            }
            catch
            {
                MessageBox.Show("Поздравляем, у вас exception! Отрисовка невозможна. Уменьшите глубину рекурсии.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Render pythagoras tree.
        /// </summary>
        /// <param name="target"> Target of the rendering. </param>
        public override void Render(Graphics target)
        {
            Pen pen = new Pen(GetColor());

            // Render next recursion level.
            if (depth < MaxDepth)
            {
                // Calculate new coordinates.
                int          newLastX = (X + lastX) / 2 + (lastY - Y) / 2;
                int          newLastY = (Y + lastY) / 2 - (lastX - X) / 2;
                DragonsCurve dc1      =
                    new DragonsCurve(depth + 1, MaxDepth, Length, X, Y, newLastX, newLastY);
                DragonsCurve dc2 =
                    new DragonsCurve(depth + 1, MaxDepth, Length, lastX, lastY, newLastX, newLastY);
                dc1.Render(target);
                dc2.Render(target);
            }
            else
            {
                // Render last level of recursion.
                target.DrawLine(pen, X, Y, lastX, lastY);
            }
        }