Po prostu napisałem mały fragment, by wygenerować fraktal Mandelbrota i wyobrazić sobie moje zdziwienie, gdy wyszło na jaw, że wszystko jest brzydkie i przekrzywione (jak widać na dole). Byłbym wdzięczny za wskazówkę, dlaczego tak się stało. To jest doświadczenie uczenia się i nie szukam dla nikogo, żeby to zrobił dla mnie, ale jestem trochę ślepy za to debugowanie. Kod generacja wykraczająca jest:Dlaczego obraz (Mandelbrot) byłby przekrzywiony i zawijany?
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
I kod obrazu (którego jestem dość pewny) jest:
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]
Czy chcesz dodać łącze do pliku obrazu? – jchl
Moje podejście do Mandelbrota: http://gist.github.com/291074 – jrockway