F# web snippets, Mandelbrot, and great things to come…
Posted by Brian on October 17, 2010
open System open System.Numerics let maxIteration = 100 let modSquared (c : Complex) = c.Real * c.Real + c.Imaginary * c.Imaginary type MandelbrotResult = | DidNotEscape | Escaped of int let mandelbrot c = let rec mandelbrotInner z iterations = if(modSquared z >= 4.0) then Escaped iterations elif iterations = maxIteration then DidNotEscape else mandelbrotInner ((z * z) + c) (iterations + 1) mandelbrotInner c 0 let chars = " .:-;!/>)|&IH%*#" for y in [-1.2..0.05..1.2] do for x in [-2.0..0.025..0.9] do match mandelbrot(Complex(x, y)) with | DidNotEscape -> Console.Write " " | Escaped i -> Console.Write chars.[i &&& 15] Console.WriteLine()
Anyway, Tomas’ tool is so cool I had to immediately try it out in a blog post before I went to sleep tonight. Here’s the output of the program, by the way:
With PDC coming soon, one imagines there may be other exciting F#-related announcements coming soon as well!