drawMandelbrot :: Coordinate -> Color
drawMandelbrot (x,y) = colorIterations $ mandelbrot (x :+ y) (0 :+ 0) 0
mandelbrot :: Complex Double -- Coordinate to test
-> Complex Double -- Iterating Z value
-> Int -- Current iteration
-> Int -- Iterations before diverging
mandelbrot c z iter
| iter > maxIter = 0
| otherwise = let z' = z^2 + c in
if magnitude(z') > 2
then iter
else mandelbrot c z' (iter+1)
drawJulia :: Coordinate -> Color
drawJulia (x,y) = colorIterations $ julia c (x :+ y) 0
julia :: Complex Double -- Constant C
-> Complex Double -- Iterating Z value
-> Int -- Current iteration
-> Int -- Iterations before diverging
julia c z iter
| iter > maxIter = 0
| otherwise = let z' = z^2 + c in
if magnitude(z') > 2
then iter
else julia c z' (iter+1)
drawShip :: Coordinate -> Color
drawShip (x,y) = colorIterations $ ship (x :+ y) (0 :+ 0) 0
ship :: Complex Double -- Coordinate to test
-> Complex Double -- Iterating Z value
-> Int -- Current iteration
-> Int -- Iterations before diverging
ship c z iter
| iter > maxIter = 0
| otherwise = let z' = (abs(realPart(z)) :+ abs(imagPart(z)))^2 + c in
if magnitude(z') > 2
then iter
else ship c z' (iter+1)
drawNewton :: Coordinate -> Color
drawNewton (x,y) = colorIterations $ newton (x :+ y) 0
newton :: Complex Double -- Coordinate to test
-> Int -- Current iteration
-> Int -- Iterations before diverging
newton z iter
| iter > maxIter = 0
| ( abs $ magnitude(r) - magnitude(z)) > minDiff = newton r (iter + 1)
| otherwise = iter
where r = z - (f z) / (f' z)
©2008 Greg Heartsfield