public async void DrawQCMenuFractal(Canvas qcFractalCanvas, Color startColor,
                                            Color endColor)
        {
            //draw qasiclover fractal in the first cell
            qcFractalCanvas.Children.Clear();
            QCFractal qcFractal = new QCFractal(qcFractalCanvas.Width / 6,
                                                startColor, endColor, 2, qcFractalCanvas);
            //start point
            Point startPoint = new Point(qcFractalCanvas.Width / 2,
                                         qcFractalCanvas.Height / 2);
            QCDrawingParams drawingParams = new QCDrawingParams(qcFractal.StartLength, 1,
                                                                startPoint, new bool[] { true, true, true, false });

            qcFractalCanvas = await qcFractal.Draw(Dispatcher, DispatcherPriority.Normal, CancellationToken.None,
                                                   drawingParams);
        }
示例#2
0
 /// <summary>
 /// Creates a list of all points, which are used in the fractal
 /// </summary>
 private void FindDots(DrawingParameters drawingParameters, Dispatcher dispatcher)
 {
     try
     {
         QCDrawingParams qcDrawingParams = (QCDrawingParams)drawingParameters;
         double          currX           = drawingParameters.CurrentCoords.X - qcDrawingParams.CurrentLength;
         double          currY           = drawingParameters.CurrentCoords.Y - qcDrawingParams.CurrentLength;
         double          length          = qcDrawingParams.CurrentLength;
         SolidColorBrush brush           = GetCurrentColor.Get(StartColor, EndColor,
                                                               drawingParameters.RecursionLevel - 1, MaxRecursionLevel - 1);
         pointsList.Add(new PointData(length, brush, new Point(currX, currY)));
         QCDrawingParams newQCParams = new QCDrawingParams(qcDrawingParams.CurrentLength / 2,
                                                           qcDrawingParams.RecursionLevel + 1, new Point(0, 0), new bool[] { });
         if (drawingParameters.RecursionLevel < MaxRecursionLevel)
         {
             bool[][] newSidesDrawability = GetNewSidesDrawability(qcDrawingParams.SidesDrawability);
             for (int i = 0; i < qcDrawingParams.SidesDrawability.Length; i++)
             {
                 if (qcDrawingParams.SidesDrawability[i])
                 {
                     newQCParams.CurrentCoords = GetNewPoint(qcDrawingParams.CurrentCoords,
                                                             qcDrawingParams.CurrentLength, i);
                     newQCParams.SidesDrawability = newSidesDrawability[i];
                     FindDots(newQCParams, dispatcher);
                 }
             }
         }
     }
     catch (OutOfMemoryException ex)
     {
         dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                 "Soft's message", MessageBoxButton.OK,
                                                 MessageBoxImage.Information));
     }
     catch (StackOverflowException ex)
     {
         dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                 "Soft's message", MessageBoxButton.OK,
                                                 MessageBoxImage.Information));
     }
     catch (Exception ex)
     {
         dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                 "Soft's message", MessageBoxButton.OK,
                                                 MessageBoxImage.Information));
     }
 }
示例#3
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();
            }
        }