private void timerSequenceOfFractals_Tick(object sender, EventArgs e)
        {
            if (!States.Any()) // if no states selected from file, return
            {
                return;
            }

            trackBarSequenceOfFractals.Maximum = timerSequenceOfFractals.Enabled ? States.Count - 1 : 0; // set trackbar levels to amount of selected files
            ticks++; // increment ticks each time timer called

            if (ticks > States.Count - 1) // if ticks exceeds the list count, set it back to zero
            {
                ticks = 0;
            }

            trackBarSequenceOfFractals.Value = ticks; // set slider to current list index
            currentState = States[ticks]; // get single state from list

            xstart = currentState.Xstart;
            ystart = currentState.Ystart;
            xzoom = currentState.Xzoom;
            yzoom = currentState.Yzoom;
            j = currentState.J;

            Mandelbrot(); // draw selected state from list
            Refresh();
        }
        private void trackBarSequenceOfFractals_Scroll(object sender, EventArgs e)
        {
            currentState = States[trackBarSequenceOfFractals.Value]; // take trackbar index and redraw the correct bitmap from list using this value

            xstart = currentState.Xstart;
            ystart = currentState.Ystart;
            xzoom = currentState.Xzoom;
            yzoom = currentState.Yzoom;
            j = currentState.J;

            Mandelbrot(); // redraw selected bitmap
            Refresh();
        }
        public void AnimateStates()
        {
            for (int i = 0; i < States.Count; i++) // loop through all loaded states
            {
                currentState = States[i]; // get single state from list

                xstart = currentState.Xstart;
                ystart = currentState.Ystart;
                xzoom = currentState.Xzoom;
                yzoom = currentState.Yzoom;
                j = currentState.J;

                Mandelbrot(); // draw first state in list
                Refresh();

                if (States.ElementAtOrDefault(i + 1) != null) // if state exists in list after current state
                {
                    nextState = States[i + 1]; // store the next state in the list

                    if (currentState.Xstart < nextState.Xstart && // current state vales lower than next state?
                           currentState.Ystart < nextState.Ystart &&
                           currentState.Xzoom > nextState.Xzoom &&
                           currentState.Yzoom > nextState.Yzoom
                        )
                    {
                        while (
                          currentState.Xstart <= nextState.Xstart &&  // yes - increase values and animate in
                          currentState.Ystart <= nextState.Ystart &&  // and draw sequences between current and next states
                          currentState.Xzoom >= nextState.Xzoom &&
                          currentState.Yzoom >= nextState.Yzoom)
                        {
                            // calculate difference between states and divide by four
                            // this value will be used to increment current state values until they exceed the next state values
                            // added 0.0001 to ensure they exceed
                            if (currentState.Xstart <= nextState.Xstart)
                            {
                                var difference = (nextState.Xstart - currentState.Xstart) / 4 + 0.00001;
                                currentState.Xstart += difference;
                            }

                            if (currentState.Ystart <= nextState.Ystart)
                            {
                                var difference = (nextState.Ystart - currentState.Ystart) / 4 + 0.00001;
                                currentState.Ystart += difference;
                            }

                            if (currentState.Xzoom >= nextState.Xzoom)
                            {
                                var difference = (currentState.Xzoom - nextState.Xzoom) / 4 + 0.000001;
                                currentState.Xzoom -= difference;
                            }

                            if (currentState.Yzoom >= nextState.Yzoom)
                            {
                                var difference = (currentState.Yzoom - nextState.Yzoom) / 4 + 0.000001;
                                currentState.Yzoom -= difference;
                            }

                            // each time the current state is changed, redraw using its values
                            xstart = currentState.Xstart;
                            ystart = currentState.Ystart;
                            xzoom = currentState.Xzoom;
                            yzoom = currentState.Yzoom;
                            this.Mandelbrot();
                            this.Refresh();
                        }
                    }
                    else // current state vales higher than next state - decreate values and animate out
                    {
                        while (
                          currentState.Xstart >= nextState.Xstart &&
                          currentState.Ystart >= nextState.Ystart &&
                          currentState.Xzoom <= nextState.Xzoom &&
                          currentState.Yzoom <= nextState.Yzoom)
                        {
                            if (currentState.Xstart >= nextState.Xstart)
                            {
                                var difference = (currentState.Xstart - nextState.Xstart) / 4 + 0.00001;
                                currentState.Xstart -= difference;
                            }

                            if (currentState.Ystart >= nextState.Ystart)
                            {
                                var difference = (currentState.Ystart - nextState.Ystart) / 4 + 0.00001;
                                currentState.Ystart -= difference;
                            }

                            if (currentState.Xzoom <= nextState.Xzoom)
                            {
                                var difference = (nextState.Xzoom - currentState.Xzoom) / 4 + 0.000001;
                                currentState.Xzoom += difference;
                            }

                            if (currentState.Yzoom <= nextState.Yzoom)
                            {
                                var difference = (nextState.Yzoom - currentState.Yzoom) / 4 + 0.000001;
                                currentState.Yzoom += difference;
                            }
                            // each time the current state is changed, redraw using its values
                            xstart = currentState.Xstart;
                            ystart = currentState.Ystart;
                            xzoom = currentState.Xzoom;
                            yzoom = currentState.Yzoom;
                            this.Mandelbrot();
                            this.Refresh();
                        }

                    }
                }
            }
        }