Skip to content

Instantly share code, notes, and snippets.

@konn
Created January 23, 2015 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konn/67b180ada53878cddb58 to your computer and use it in GitHub Desktop.
Save konn/67b180ada53878cddb58 to your computer and use it in GitHub Desktop.
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