Mandelbrot avec haskell

Voici le code “obfusqué” :

Pour le lancer, haskell doit être installé. Puis vous devez écrire dans un terminal :

ghc –make animandel.hs && animandel

Voici le résultat après 50 itérations.

###@@@@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&WWOOClbUOWW&&$$$$$$$$$$$$$$
##@@@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&WWUCUb; ,jUOWW&&&$$$$$$$$$$$$
#@@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&WWWWWUb       ooCWW&&&&&&$$$$$$$$
@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&WWWWWWWWOU         uUOWWWW&&&&&&$$$$$
@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&WOUObUOOOUUUCbi      rbCUUUOWWWWWOUW&$$$
@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&&WWWUcr,iiCb                o wUUUUUC;OW&$$
$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&&&&&&WWWWOUC,                         j    llW&&$
$$$$$$$$$$$$$$$$$$$$$&&&&&&&&&&&&WWWWWWOCCbi                              bWWW&&
$$$$$$$$$$$$$$$$$&&WWWWWWW&&&WWWWWWWWOUo                                 jUOWW&&
$$$$$$$$$$$$$$&&&WWOwOOWWWOUUOWWWWWOOUbw                                  j.blW&
$$$$$$$$$$$&&&&&WWWObiijbUCl bCiUUUUUCj,                                    bOW&
$$$$$$$$$&&&&&&&WWWOUbw  ;      oobCbl                                     jUWW&
$$$$$$$&&&&&&&WWWWOcbi             ij                                      jUW&&
$$$$$&&WWWWWWWOwUUCbw                                                       WW&&
WWWOWWWWWWWWWUUbo                                                         UWWW&&
:                                                                      wbUOWW&&&
WWWOWWWWWWWWWUUbo                                                         UWWW&&
$$$$$&&WWWWWWWOwUUCbw                                                       WW&&
$$$$$$$&&&&&&&WWWWOcbi             ij                                      jUW&&
$$$$$$$$$&&&&&&&WWWOUbw  ;      oobCbl                                     jUWW&
$$$$$$$$$$$&&&&&WWWObiijbUCl bCiUUUUUCj,                                    bOW&
$$$$$$$$$$$$$$&&&WWOwOOWWWOUUOWWWWWOOUbw                                  j.blW&
$$$$$$$$$$$$$$$$$&&WWWWWWW&&&WWWWWWWWOUo                                 jUOWW&&
$$$$$$$$$$$$$$$$$$$$$&&&&&&&&&&&&WWWWWWOCCbi                              bWWW&&
$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&&&&&&WWWWOUC,                         j    llW&&$
@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&&WWWUcr,iiCb                o wUUUUUC;OW&$$

Here is the more readable version. I believe with this far more readable version, no more explanation is needed.

nbvert = 30
nbhor = 79
zoomfactor = 1.01
init_bottom_left = C (-2.0,-2.0)
init_top_right   = C (3.0,2.0)
interrest        = C (-1.713,-0.000)

newtype Complex = C (Float,Float) deriving (Show,Eq)
instance Num Complex where
    fromInteger n     = C (fromIntegral n,0.0)
    C (x,y) * C (z,t) = C (z*x - y*t, y*z + x*t)
    C (x,y) + C (z,t) = C (x+z, y+t)
    abs (C (x,y))     = C (sqrt (x*x + y*y),0.0)
    signum (C (x,y))  = C (signum x , 0.0)

real :: Complex -> Float
real (C (x,y))    = x
im :: Complex -> Float
im   (C (x,y))    = y

cabs :: Complex -> Float
cabs = real.abs

f :: Complex -> Complex -> Int -> Int
f c z 0 = 0
f c z n = if (cabs z > 2) then n else f c ((z*z)+c) (n-1) 

bmandel bottomleft topright = map (\z -> (f (C z) (C(0,0)) 32, (fst z > right - hstep/2 ))) [(x,y) | y <- [bottom,(bottom + vstep)..top], x<-[left,(left + hstep)..right]]
    where
        top = im topright
        bottom = im bottomleft
        left = real bottomleft
        right = real topright
        vstep=(top-bottom)/nbvert
        hstep=(right-left)/nbhor

mandel :: (Complex,Complex) -> String
mandel (bottomleft,topright) = concat $ map treat $ bmandel bottomleft topright
    where
        treat (i,jump) = " .,:;rcuowijlbCUOW&$@#" !! (div (i*22) 32):rst jump
        rst True = "\n"
        rst False = ""

cdiv :: Complex -> Float -> Complex
cdiv (C(x,y)) r = C(x/r, y/r) 
cmul :: Complex -> Float -> Complex
cmul (C(x,y)) r = C(x*r, y*r) 

zoom :: Complex -> Complex -> Complex -> Float -> (Complex,Complex)
zoom bl tr center magn = (f bl, f tr)
    where
        f point = ((center `cmul` magn) + point ) `cdiv` (magn + 1)

main = do
    x <- getContents
    putStrLn $ infinitemandel 0
    where
        window n = zoom init_bottom_left init_top_right interrest (zoomfactor**n) 
        infinitemandel n = mandel (window n) ++ "\x1b[H\x1b[25A" ++ infinitemandel (n+1)