/// <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)); } }
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); }
/// <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); }
/// <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(); } }