|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Matt Thalman <mthalman@microsoft.com> |
| 3 | +Date: Wed, 3 Jan 2024 16:14:20 -0600 |
| 4 | +Subject: [PATCH] Remove Mandelbrot example due to license |
| 5 | + |
| 6 | +Backport: https://github.com/spectreconsole/spectre.console/pull/1426 |
| 7 | +--- |
| 8 | + examples/Console/Canvas/Mandelbrot.cs | 86 --------------------------- |
| 9 | + 1 file changed, 86 deletions(-) |
| 10 | + delete mode 100644 examples/Console/Canvas/Mandelbrot.cs |
| 11 | + |
| 12 | +diff --git a/examples/Console/Canvas/Mandelbrot.cs b/examples/Console/Canvas/Mandelbrot.cs |
| 13 | +deleted file mode 100644 |
| 14 | +index da804a4..0000000 |
| 15 | +--- a/examples/Console/Canvas/Mandelbrot.cs |
| 16 | ++++ /dev/null |
| 17 | +@@ -1,86 +0,0 @@ |
| 18 | +-/* |
| 19 | +-Ported from: https://rosettacode.org/wiki/Mandelbrot_set#C.23 |
| 20 | +-Licensed under GNU Free Documentation License 1.2 |
| 21 | +-*/ |
| 22 | +- |
| 23 | +-using System; |
| 24 | +-using Spectre.Console; |
| 25 | +- |
| 26 | +-namespace Canvas; |
| 27 | +- |
| 28 | +-public static class Mandelbrot |
| 29 | +-{ |
| 30 | +- private const double MaxValueExtent = 2.0; |
| 31 | +- |
| 32 | +- private struct ComplexNumber |
| 33 | +- { |
| 34 | +- public double Real { get; } |
| 35 | +- public double Imaginary { get; } |
| 36 | +- |
| 37 | +- public ComplexNumber(double real, double imaginary) |
| 38 | +- { |
| 39 | +- Real = real; |
| 40 | +- Imaginary = imaginary; |
| 41 | +- } |
| 42 | +- |
| 43 | +- public static ComplexNumber operator +(ComplexNumber x, ComplexNumber y) |
| 44 | +- { |
| 45 | +- return new ComplexNumber(x.Real + y.Real, x.Imaginary + y.Imaginary); |
| 46 | +- } |
| 47 | +- |
| 48 | +- public static ComplexNumber operator *(ComplexNumber x, ComplexNumber y) |
| 49 | +- { |
| 50 | +- return new ComplexNumber(x.Real * y.Real - x.Imaginary * y.Imaginary, |
| 51 | +- x.Real * y.Imaginary + x.Imaginary * y.Real); |
| 52 | +- } |
| 53 | +- |
| 54 | +- public double Abs() |
| 55 | +- { |
| 56 | +- return Real * Real + Imaginary * Imaginary; |
| 57 | +- } |
| 58 | +- } |
| 59 | +- |
| 60 | +- public static Spectre.Console.Canvas Generate(int width, int height) |
| 61 | +- { |
| 62 | +- var canvas = new Spectre.Console.Canvas(width, height); |
| 63 | +- |
| 64 | +- var scale = 2 * MaxValueExtent / Math.Min(canvas.Width, canvas.Height); |
| 65 | +- for (var i = 0; i < canvas.Height; i++) |
| 66 | +- { |
| 67 | +- var y = (canvas.Height / 2 - i) * scale; |
| 68 | +- for (var j = 0; j < canvas.Width; j++) |
| 69 | +- { |
| 70 | +- var x = (j - canvas.Width / 2) * scale; |
| 71 | +- var value = Calculate(new ComplexNumber(x, y)); |
| 72 | +- canvas.SetPixel(j, i, GetColor(value)); |
| 73 | +- } |
| 74 | +- } |
| 75 | +- |
| 76 | +- return canvas; |
| 77 | +- } |
| 78 | +- |
| 79 | +- private static double Calculate(ComplexNumber c) |
| 80 | +- { |
| 81 | +- const int MaxIterations = 1000; |
| 82 | +- const double MaxNorm = MaxValueExtent * MaxValueExtent; |
| 83 | +- |
| 84 | +- var iteration = 0; |
| 85 | +- var z = new ComplexNumber(); |
| 86 | +- do |
| 87 | +- { |
| 88 | +- z = z * z + c; |
| 89 | +- iteration++; |
| 90 | +- } while (z.Abs() < MaxNorm && iteration < MaxIterations); |
| 91 | +- |
| 92 | +- return iteration < MaxIterations |
| 93 | +- ? (double)iteration / MaxIterations |
| 94 | +- : 0; |
| 95 | +- } |
| 96 | +- |
| 97 | +- private static Color GetColor(double value) |
| 98 | +- { |
| 99 | +- const double MaxColor = 256; |
| 100 | +- const double ContrastValue = 0.2; |
| 101 | +- return new Color(0, 0, (byte)(MaxColor * Math.Pow(value, ContrastValue))); |
| 102 | +- } |
| 103 | +-} |
0 commit comments