Example #1
0
        /// <summary>
        /// When pictureBox redraws.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox_Paint(object sender, PaintEventArgs e)
        {
            switch (pickedFractal)
            {
            case 0:
                koch = new KochCurve(depth, sender, e, p);
                koch.DrawFractal(p);
                break;

            case 1:
                triangle = new TriangleSerpinsky(depth, sender, e, p);
                triangle.DrawFractal(p);
                break;

            case 2:
                tree            = new FractalTree(depth, sender, e, p);
                tree.LengthCoef = coef;
                tree.LeftAngle  = leftAngle;
                tree.RightAngle = rightAngle;
                tree.DrawFractal(p);
                break;

            case 3:
                carpet = new CarpetSerpinskiy(depth, sender, e, p);
                carpet.DrawFractal(p);
                break;

            case 4:
                cantor = new CantorSet(depth, sender, e, p);
                cantor.SetDist(cantorDist);
                cantor.DrawFractal(p);
                break;
            }
        }
Example #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;
            }
        }
        /// <summary>
        /// Render cantor set.
        /// </summary>
        /// <param name="target"> Target of the rendering. </param>
        public override void Render(Graphics target)
        {
            Pen pen = new Pen(GetColor());

            // Draw line.
            target.FillRectangle(pen.Brush, X, Y, Length, width);

            // Render next recursion level.
            if (depth < MaxDepth)
            {
                // Stop if fractal is too small.
                if (Length / 3 == 0)
                {
                    return;
                }

                CantorSet cs1 =
                    new CantorSet(depth + 1, MaxDepth, Length / 3, X, Y + width * 2);
                cs1.Render(target);
                CantorSet cs2 =
                    new CantorSet(depth + 1, MaxDepth, Length / 3, X + Length / 3 * 2, Y + width * 2);
                cs2.Render(target);
            }
        }