Exemplo n.º 1
0
        private void AddBranch(FractalLine parent, int Depth)
        {
            if (Depth > SplitDepth || Draw == false)
            {
                return;
            }

            double Angle1 = parent.m_Angle - AngleDelta;
            double Angle2 = parent.m_Angle + AngleDelta;

            FractalLine line  = new FractalLine(parent.m_End, (int)(parent.CalcLength() * ShrinkRate), Angle1, parent);
            FractalLine line2 = new FractalLine(parent.m_End, (int)(parent.CalcLength() * ShrinkRate), Angle2, parent);

            System.Threading.Thread.Sleep(Int32.Parse(txtAnimDelay.Text));

            //UI commands must be invoked on ui thread
            Action a = () => DrawCanvas.Refresh();

            InvokeUI(a);

            /*Take turns on which side goes first,
             * This prevents one side of the tree from completing first*/
            if (Depth % 2 == 0)
            {
                AddBranch(line, Depth + 1);
                AddBranch(line2, Depth + 1);
            }
            else
            {
                AddBranch(line2, Depth + 1);
                AddBranch(line, Depth + 1);
            }
        }
Exemplo n.º 2
0
        private void BtnDraw_Click(object sender, EventArgs e)
        {
            Draw = true;
            UpdateParameters();
            //Run in new thread to keep UI responsive
            Task.Run(() =>
            {
                int MiddleCanvasX = DrawCanvas.Size.Width / 2;
                Trunk             = new FractalLine(new Point(MiddleCanvasX, DrawCanvas.Size.Height), StartHeight, 90, null);

                AddBranch(Trunk, 0);
                DrawCanvas.Invalidate();
            });
        }
Exemplo n.º 3
0
        public FractalLine(Point Start, int Length, double Degrees, FractalLine parent)
        {
            m_Children = new List <FractalLine>();
            m_Start    = Start;

            m_Angle = Degrees;
            double Radians = (Math.PI / 180.0) * Degrees;
            int    Y       = (int)(Math.Sin(Radians) * Length);
            int    X       = (int)(Math.Cos(Radians) * Length);

            m_End = new Point(Start.X + X, Start.Y - Y);

            m_Parent = parent;
            if (m_Parent != null)
            {
                m_Parent.m_Children.Add(this);
            }
        }