Skip to content

Instantly share code, notes, and snippets.

@tatyusa
Created February 28, 2014 03:29
Show Gist options
  • Save tatyusa/9264637 to your computer and use it in GitHub Desktop.
Save tatyusa/9264637 to your computer and use it in GitHub Desktop.
Draw Julia Set of f(z) = z^2 + (-0.765+0.12i) by Haskell
import Data.Complex
type R = Double
type C = Complex R
-- 反復合成の定義
(^:) :: (C -> C) -> Int -> C -> C
(^:) f n = (flip (!!) n).(iterate f)
-- 計算する矩形領域
domain :: [C]
domain = [x :+ y | x <- interval, y <- interval]
where interval = [-2.0,-1.999..2.0]
-- 反復する関数
f :: C -> C
f z = z*z + ((-0.765):+0.12)
-- 計算した値をCSVに整形して出力
outputCSV :: [C] -> IO ()
outputCSV zs = mapM_ putStrLn $ map form zs
where form z = (show $ realPart z)++","++(show $ imagPart z)
main :: IO ()
main = outputCSV $ map snd $ filter condition $ zip (map (f^:100) domain) domain
where condition z = (realPart.abs.fst) z < 5
@tatyusa
Copy link
Author

tatyusa commented Feb 28, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment