public async void DrawSCMenuFractal(Canvas scFractalCanvas, Color startColor,
                                            Color endColor)
        {
            //draw the Serpinskiy's triangle int the second cell
            scFractalCanvas.Children.Clear();
            SCFractal scFractal = new SCFractal(2.0 * scFractalCanvas.Width / 3,
                                                startColor, endColor, 2, scFractalCanvas);
            Point           startPoint      = new Point(scFractalCanvas.Width / 2, scFractalCanvas.Height / 2);
            SCDrawingParams scDrawingParams = new SCDrawingParams(scFractal.StartLength,
                                                                  1, startPoint);

            scFractal.InitialDraw(scDrawingParams);
            scFractalCanvas = await scFractal.Draw(Dispatcher, DispatcherPriority.Normal, CancellationToken.None,
                                                   scDrawingParams);
        }
Ejemplo n.º 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();
            }
        }