Skip to content

Instantly share code, notes, and snippets.

@konn
Created Jan 23, 2015
Embed
What would you like to do?
module Main where
import Data.Complex
import Data.List
import Data.Monoid
import Data.Ratio
errorRange = 1e-20
calculate :: Complex Double -> [Double]
calculate c = map magnitude $ iterate ((+c).(^^2)) 0
divergence :: Int -> Complex Double -> Maybe Int
divergence max c =
let targs = take max $ calculate c
in if last targs < 2
then Nothing
else findIndex (getAny.((Any . isInfinite) `mappend` (Any . (>2)))) targs
step = 0.0045
plane :: [[Complex Double]]
plane = [[x :+ y | x <- [-2.0,-2.0+step..1.25]]
| y <- [-1.5,-1.5+step..1.5]
]
main :: IO ()
main =
writeFile "mandelbrot.csv" .
intercalate "\n" .
map (intercalate "," . map show) $ map (map (maybe 101 id . divergence 100)) plane
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment