/// <summary>
        /// Render fractal.
        /// </summary>
        /// <param name="e"> Target of the rendering. </param>
        public override void Render(Graphics target)
        {
            Pen pen    = new Pen(GetColor());
            int height = (int)(Length * Math.Sin(Math.PI / 3));

            // Draw triangle.
            target.DrawLine(pen, X, Y + height, X + Length, Y + height);
            target.DrawLine(pen, X, Y + height, X + Length / 2, Y);
            target.DrawLine(pen, X + Length, Y + height, X + Length / 2, Y);
            // Render next recursion level.
            if (depth < MaxDepth)
            {
                // Stop if fractal is too small.
                if (Length / 2 == 0)
                {
                    return;
                }
                SierpinskiTriangle st1 =
                    new SierpinskiTriangle(depth + 1, MaxDepth, Length / 2, X, Y + height / 2);
                st1.Render(target);
                SierpinskiTriangle st2 =
                    new SierpinskiTriangle(depth + 1, MaxDepth, Length / 2, X + Length / 2, Y + height / 2);
                st2.Render(target);
                SierpinskiTriangle st3 =
                    new SierpinskiTriangle(depth + 1, MaxDepth, Length / 2, X + Length / 4, Y);
                st3.Render(target);
            }
        }
Exemplo n.º 2
0
        public void Drawing()
        {
            switch (fractalSelection.SelectedItem)
            {
            case "Дерево Пифагора":
                pythagoreanTree = new PythagoreanTree((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value,
                                                      (flowLayoutPanel1.Height - 20) * trackBarZoom.Value,
                                                      (int)segmentLength.Value * trackBarZoom.Value, (int)angleFirst.Value, (int)angleSecond.Value);
                pictureBox.Image = pythagoreanTree.Map;
                break;

            case "Кривая Коха":
                kochCurve = new KochCurve((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value,
                                          (flowLayoutPanel1.Height - 20) * trackBarZoom.Value);
                pictureBox.Image = kochCurve.Map;
                break;

            case "Ковёр Серпинского":
                carpet = new SierpinskiCarpet((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value,
                                              (flowLayoutPanel1.Height - 20) * trackBarZoom.Value);
                pictureBox.Image = carpet.Map;
                break;

            case "Треугольник Серпинского":
                triangle = new SierpinskiTriangle((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value,
                                                  (flowLayoutPanel1.Height - 20) * trackBarZoom.Value);
                pictureBox.Image = triangle.Map;
                break;

            case "Множество Кантора":
                cantorSet = new CantorSet((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value,
                                          (flowLayoutPanel1.Height - 20) * trackBarZoom.Value, (int)segmentLength.Value * trackBarZoom.Value);
                pictureBox.Image = cantorSet.Map;
                break;
            }
        }