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