Why would an image (the Mandelbrot) be skewed and wrap around?

Posted by Sean D on Stack Overflow See other posts from Stack Overflow or by Sean D
Published on 2010-06-02T12:46:10Z Indexed on 2010/06/02 13:44 UTC
Read the original article Hit count: 228

Filed under:
|
|

So I just wrote a little snippet to generate the Mandelbrot fractal and imagine my surprise when it came out all ugly and skewed (as you can see at the bottom). I'd appreciate a point in the direction of why this would even happen. It's a learning experience and I'm not looking for anyone to do it for me, but I'm kinda at a dead end debugging it. The offending generation code is:

 module Mandelbrot where
 import Complex
 import Image

 main = writeFile "mb.ppm" $ imageMB 1000

 mandelbrotPixel x y = mb (x:+y) (0:+0) 0

 mb c x iter
  | magnitude x > 2  = iter
  | iter >= 255   = 255
  | otherwise   = mb c (c+q^2) (iter+1)
  where
   q = x --Mandelbrot
   --q = (abs.realPart $ x) :+ (abs.imagPart $ x) --Burning Ship

 argandPlane x0 x1 y0 y1 width height =
  [(x,y)| y<-[y1,(y1-dy)..y0], --traverse from
    x<-[x0,(x0+dx)..x1]] --top-left to bottom-right
  where 
   dx = (x1 - x0)/width
   dy = (y1 - y0)/height

 drawPicture :: (a->b->c)->(c->Colour)->[(a,b)]->Image
 drawPicture function colourFunction plane =
  map (colourFunction.uncurry function)  plane

 imageMB s = createPPM s s $ 
  drawPicture mandelbrotPixel (\x->[x,x,x]) $
  argandPlane (-1.8) (-1.7) (0.02) 0.055 s' s'
  where s' = fromIntegral s

And the image code (which I'm fairly confident in) is:

module Image where

 type Colour = [Int]
 type Image = [Colour]

 createPPM :: Int -> Int -> Image -> String
 createPPM w h i =
  concat ["P3 ", show w, " ", show h, " 255\n",
    unlines.map (unwords.map show) $ i]

Ugly Mandelskew thing

© Stack Overflow or respective owner

Related posts about image

Related posts about haskell