Esempio n. 1
0
 /// <summary>
 /// Creates a list of all points, which are used in the fractal
 /// </summary>
 private void FindDots(DrawingParameters drawingParameters, Dispatcher dispatcher)
 {
     try
     {
         SCDrawingParams scDrawingParams = (SCDrawingParams)drawingParameters;
         double          currX           = drawingParameters.CurrentCoords.X;
         double          currY           = drawingParameters.CurrentCoords.Y;
         double          side            = scDrawingParams.CurrentLength;
         Point           centerPoint     = new Point(currX, currY);
         SolidColorBrush brush           = GetCurrentColor.Get(StartColor, EndColor,
                                                               drawingParameters.RecursionLevel - 1, MaxRecursionLevel - 1);
         pointsList.Add(new PointData(side, brush, new Point(currX, currY)));
         SCDrawingParams newQCParams = new SCDrawingParams(scDrawingParams.CurrentLength / 2,
                                                           scDrawingParams.RecursionLevel + 1, new Point(0, 0));
         if (scDrawingParams.RecursionLevel < MaxRecursionLevel)
         {
             SCDrawingParams newDrawingParams = new SCDrawingParams(side / 2,
                                                                    scDrawingParams.RecursionLevel + 1,
                                                                    new Point(centerPoint.X, centerPoint.Y -
                                                                              side * Math.Sqrt(3) / 8));
             FindDots(newDrawingParams, dispatcher);
             newDrawingParams = new SCDrawingParams(side / 2,
                                                    scDrawingParams.RecursionLevel + 1,
                                                    new Point(centerPoint.X - side / 4.0, centerPoint.Y +
                                                              side * Math.Sqrt(3) / 8));
             FindDots(newDrawingParams, dispatcher);
             newDrawingParams = new SCDrawingParams(side / 2,
                                                    scDrawingParams.RecursionLevel + 1,
                                                    new Point(centerPoint.X + side / 4.0, centerPoint.Y +
                                                              side * Math.Sqrt(3) / 8));
             FindDots(newDrawingParams, 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));
     }
 }
Esempio n. 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));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Draws the first main triangle
        /// </summary>
        public void InitialDraw(DrawingParameters drawingParameters)
        {
            SCDrawingParams scDrawingParams = (SCDrawingParams)drawingParameters;

            Point[] tPointsArr = GetTrianglePoints(scDrawingParams.CurrentCoords,
                                                   scDrawingParams.CurrentLength);
            PointCollection tPointsCollection = new PointCollection(tPointsArr);
            Polyline        line = new Polyline
            {
                Points          = tPointsCollection,
                StrokeThickness = 0.3,
                Stroke          = GetCurrentColor.Get(StartColor, EndColor,
                                                      scDrawingParams.RecursionLevel, MaxRecursionLevel)
            };

            MainCanvas.Children.Add(line);
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a list of all points, which are used in the fractal
 /// </summary>
 private void FindDots(DrawingParameters drawingParameters, Dispatcher dispatcher)
 {
     try
     {
         NFDrawingParams nfDrawingParams = (NFDrawingParams)drawingParameters;
         Point[]         tPointsArr      = GetFractalPoints(nfDrawingParams.CurrentCoords,
                                                            nfDrawingParams.CurrentLength);
         SolidColorBrush brush = GetCurrentColor.Get(StartColor, EndColor,
                                                     nfDrawingParams.RecursionLevel - 1, MaxRecursionLevel - 1);
         nfFractalPointsList.Add(new NFFractalPointData(tPointsArr, brush));
         if (nfDrawingParams.RecursionLevel < MaxRecursionLevel)
         {
             //define new drawing params for four new elements and find the data about them
             NFDrawingParams newDrawingParams = new NFDrawingParams(
                 nfDrawingParams.CurrentLength / 2, nfDrawingParams.RecursionLevel + 1,
                 tPointsArr[2]);
             FindDots(newDrawingParams, dispatcher);
             newDrawingParams.CurrentCoords = tPointsArr[3];
             FindDots(newDrawingParams, dispatcher);
             newDrawingParams.CurrentCoords = tPointsArr[4];
             FindDots(newDrawingParams, dispatcher);
             newDrawingParams.CurrentCoords = tPointsArr[5];
             FindDots(newDrawingParams, 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));
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Draws the farctal itself, based on the list of points we created before
        /// </summary>
        public async override Task <Canvas> Draw(Dispatcher dispatcher, DispatcherPriority priority,
                                                 CancellationToken token, DrawingParameters drawingParameters)
        {
            try
            {
                await dispatcher.BeginInvoke(new Action(() => FindDots(drawingParameters, dispatcher)));

                for (int i = 0; i < pointsList.Count; i++)
                {
                    if (token != CancellationToken.None && token.IsCancellationRequested)
                    {
                        throw new TaskCanceledException();
                    }
                    dispatcher.Invoke(new Action(() =>
                    {
                        try
                        {
                            //draw. firstly create an ellipse with the given size
                            Ellipse ellipse = new Ellipse
                            {
                                Width  = pointsList[i].Length * 2,
                                Height = pointsList[i].Length * 2,
                                Fill   = pointsList[i].CurrentBrush
                            };
                            //set the position of the created ellipse and add attach to the parent
                            Canvas.SetLeft(ellipse, pointsList[i].Coords.X);
                            Canvas.SetTop(ellipse, pointsList[i].Coords.Y);
                            MainCanvas.Children.Add(ellipse);
                        }
                        catch (NullReferenceException ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                        catch (OutOfMemoryException ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                    }), priority);
                }
                return(MainCanvas);
            }
            catch (TaskCanceledException)
            {
                dispatcher.Invoke(() => MessageBox.Show("Drawing task " +
                                                        "was canceled", "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 (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 (Exception ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Draws the farctal itself, based on the list of points we created before
        /// </summary>
        public override async Task <Canvas> Draw(Dispatcher dispatcher, DispatcherPriority priority,
                                                 CancellationToken token, DrawingParameters drawingParameters)
        {
            try
            {
                await dispatcher.BeginInvoke(new Action(() => FindDots(drawingParameters, dispatcher)));

                for (int i = 0; i < nfFractalPointsList.Count; i++)
                {
                    if (token != CancellationToken.None && token.IsCancellationRequested)
                    {
                        throw new TaskCanceledException();
                    }
                    dispatcher.Invoke(new Action(() =>
                    {
                        try
                        {
                            Line horizontalLine = new Line
                            {
                                Stroke = nfFractalPointsList[i].CurrentBrush,
                                X1     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[0].X,
                                Y1     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[0].Y,
                                X2     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[1].X,
                                Y2     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[1].Y,
                            };
                            Line leftVerticalLine = new Line
                            {
                                Stroke = nfFractalPointsList[i].CurrentBrush,
                                X1     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[2].X,
                                Y1     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[2].Y,
                                X2     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[3].X,
                                Y2     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[3].Y,
                            };
                            Line rightVerticalLine = new Line
                            {
                                Stroke = nfFractalPointsList[i].CurrentBrush,
                                X1     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[4].X,
                                Y1     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[4].Y,
                                X2     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[5].X,
                                Y2     = ((NFFractalPointData)nfFractalPointsList[i]).PointsArr[5].Y,
                            };
                            //add the lines to the canvas
                            MainCanvas.Children.Add(horizontalLine);
                            MainCanvas.Children.Add(leftVerticalLine);
                            MainCanvas.Children.Add(rightVerticalLine);
                        }
                        catch (NullReferenceException ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                        catch (OutOfMemoryException ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                    }), priority);
                }
                return(MainCanvas);
            }
            catch (TaskCanceledException)
            {
                dispatcher.Invoke(() => MessageBox.Show("Drawing task " +
                                                        "was canceled", "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 (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 (Exception ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
        }
Esempio n. 7
0
 public abstract Task <Canvas> Draw(Dispatcher dispatcher, DispatcherPriority priority,
                                    CancellationToken token, DrawingParameters drawingParameters);
Esempio n. 8
0
        /// <summary>
        /// Draws the farctal itself, based on the list of points we created before
        /// </summary>
        public async override Task <Canvas> Draw(Dispatcher dispatcher, DispatcherPriority priority,
                                                 CancellationToken token, DrawingParameters drawingParameters)
        {
            try
            {
                await dispatcher.BeginInvoke(new Action(() => FindDots(drawingParameters, dispatcher)));

                await dispatcher.BeginInvoke(new Action(() => InitialDraw(drawingParameters)));

                for (int i = 0; i < pointsList.Count; i++)
                {
                    if (token != CancellationToken.None && token.IsCancellationRequested)
                    {
                        throw new TaskCanceledException();
                    }
                    dispatcher.Invoke(new Action(() =>
                    {
                        try
                        {
                            Point centerPoint  = pointsList[i].Coords;
                            double side        = pointsList[i].Length;
                            Point[] tPointsArr = new Point[]
                            {
                                new Point(centerPoint.X - side / 4, centerPoint.Y - 0.3),
                                new Point(centerPoint.X + side / 4, centerPoint.Y - 0.3),
                                new Point(centerPoint.X, centerPoint.Y + side * Math.Sqrt(3) / 4 - 0.3),
                                new Point(centerPoint.X - side / 4, centerPoint.Y - 0.3),
                            };
                            PointCollection tPointsCollection = new PointCollection(tPointsArr);
                            Polyline line = new Polyline
                            {
                                Points          = tPointsCollection,
                                StrokeThickness = 0.3,
                                Stroke          = pointsList[i].CurrentBrush
                            };
                            MainCanvas.Children.Add(line);
                        }
                        catch (NullReferenceException ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                        catch (OutOfMemoryException ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Soft's message", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                        }
                    }), priority);
                }
                return(MainCanvas);
            }
            catch (TaskCanceledException)
            {
                dispatcher.Invoke(() => MessageBox.Show("Drawing task " +
                                                        "was canceled", "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
            catch (IndexOutOfRangeException ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message));
                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 (Exception ex)
            {
                dispatcher.Invoke(() => MessageBox.Show(ex.Message,
                                                        "Soft's message", MessageBoxButton.OK,
                                                        MessageBoxImage.Information));
                return(null);
            }
        }