Alors j'ai juste écrit un petit extrait pour générer la fractale de Mandelbrot et imaginez ma surprise quand elle est sortie laide et déformée (comme vous pouvez le voir en bas). J'apprécierais un point dans la direction de pourquoi cela arriverait même. C'est une expérience d'apprentissage et je ne cherche personne pour le faire pour moi, mais je suis un peu dans une impasse pour le déboguer. Le code de génération incriminée est:Pourquoi une image (le Mandelbrot) serait-elle faussée et entourée?
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 = map (colourFunction . uncurry function)
imageMB s = createPPM s s
$ drawPicture mandelbrotPixel (replicate 3)
$ argandPlane (-1.8) (-1.7) (0.02) 0.055 s' s'
where s' = fromIntegral s
Et le code d'image (que je suis assez confiant dans) est:
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]
Vouliez-vous ajouter un lien vers le fichier image? – jchl
Ma prise sur Mandelbrot: http://gist.github.com/291074 – jrockway