public async void DrawNFMenuFractal(Canvas nfFractalCanvas, Color startColor,
                                            Color endColor)
        {
            //draw the H-Fractal in the third cell
            nfFractalCanvas.Children.Clear();
            NFFractal nfFractal = new NFFractal(nfFractalCanvas.Width / 2,
                                                startColor, endColor, 2, nfFractalCanvas);
            Point startPoint = new Point(nfFractalCanvas.Width / 2,
                                         nfFractalCanvas.Height / 2);
            NFDrawingParams nfDrawingParams = new NFDrawingParams(nfFractal.StartLength,
                                                                  1, startPoint);

            nfFractalCanvas = await nfFractal.Draw(Dispatcher, DispatcherPriority.Normal, CancellationToken.None,
                                                   nfDrawingParams);
        }
Exemple #2
0
        /// <summary>
        /// Draws a fractal on the main Canvas using the several pararmeters
        /// to initalize the drawing process
        /// </summary>
        public async Task <Canvas> DrawFractal(double length, int depth, Point startPoint,
                                               Dispatcher dispatcher, CancellationToken token)
        {
            try
            {
                Disable();
                switch (CurrentFractal)
                {
                case 1:
                    QCFractal qcFractal = new QCFractal(length,
                                                        StartColor, EndColor, depth, MainCanvas);
                    DrawingParameters qcParams = new QCDrawingParams(length, 1,
                                                                     startPoint, QCSidesDrawability);
                    if (DispatcherPriority == DispatcherPriority.Send)
                    {
                        TempCanvas = new Canvas
                        {
                            Width      = 5000,
                            Height     = 5000,
                            Background = new SolidColorBrush(Color.FromRgb(255, 255, 255))
                        };
                        qcFractal.MainCanvas = TempCanvas;
                        return(await Task.Run(() => qcFractal.Draw(dispatcher,
                                                                   DispatcherPriority, token, qcParams)));
                    }
                    else
                    {
                        await Task.Run(() => qcFractal.Draw(dispatcher,
                                                            DispatcherPriority, token, qcParams));
                    }
                    return(null);

                case 2:
                    SCFractal scFractal = new SCFractal(length,
                                                        StartColor, EndColor,
                                                        depth, MainCanvas);
                    DrawingParameters scParams = new SCDrawingParams(length, 1,
                                                                     startPoint);
                    scFractal.InitialDraw(scParams);
                    if (DispatcherPriority == DispatcherPriority.Send)
                    {
                        TempCanvas = new Canvas
                        {
                            Width      = 5000,
                            Height     = 5000,
                            Background = new SolidColorBrush(Color.FromRgb(255, 255, 255))
                        };
                        scFractal.MainCanvas = TempCanvas;
                        return(await Task.Run(() => scFractal.Draw(dispatcher, DispatcherPriority,
                                                                   token, scParams)));
                    }
                    else
                    {
                        await Task.Run(() => scFractal.Draw(dispatcher, DispatcherPriority,
                                                            token, scParams));
                    }
                    return(null);

                case 3:
                    NFFractal nfFractal = new NFFractal(length,
                                                        StartColor, EndColor,
                                                        depth, MainCanvas);
                    DrawingParameters nfParams = new NFDrawingParams(length, 1,
                                                                     startPoint);
                    if (DispatcherPriority == DispatcherPriority.Send)
                    {
                        TempCanvas = new Canvas
                        {
                            Width      = 5000,
                            Height     = 5000,
                            Background = new SolidColorBrush(Color.FromRgb(255, 255, 255))
                        };
                        nfFractal.MainCanvas = TempCanvas;
                        return(await Task.Run(() => nfFractal.Draw(dispatcher, DispatcherPriority,
                                                                   token, nfParams)));
                    }
                    else
                    {
                        await Task.Run(() => nfFractal.Draw(dispatcher, DispatcherPriority,
                                                            token, nfParams));
                    }
                    return(null);

                default:
                    MessageBox.Show("The fatal error happened, this should be never seen...");
                    return(null);
                }
            }
            catch (OutOfMemoryException ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
            catch (StackOverflowException ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
            catch (IndexOutOfRangeException ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
            catch (NullReferenceException ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
            catch (TaskCanceledException ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
            catch (Exception ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
            finally
            {
                Enable();
            }
        }