그래서 Mandelbrot 프랙탈을 생성하고 모든 추악하고 왜곡 된 (내면에서 볼 수있는 것처럼) 때가 왔을 때의 놀라운 모습을 상상해 보겠습니다. 나는 이것이 왜 일어날 지에 대한 방향으로 한 점을 높이 평가할 것이다. 그것은 학습 경험이고 나는 그것을 위해 그것을 할 누군가를 찾고 있지 않다. 그러나 나는 그것을 디버깅하는 막 다른 골목에 좀있다. 잘못된 생성 코드는 다음과 같습니다왜 이미지 (만델 브로)가 비뚤어지고 랩어요?
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
그리고 (나는에 매우 확신) 이미지 코드는 다음과 같습니다
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]
이미지 파일에 링크를 추가 하시겠습니까? – jchl
만델 브로트 (Mandelbrot) : http://gist.github.com/291074 – jrockway