--- /afs/athena.mit.edu/user/k/e/kenta/.shd/www/six/snowflake/snowflake.hs 2005-01-19 03:27:15.000000002 -0500 +++ snowflake.hs 2014-10-28 06:01:15.596026084 -0400 @@ -1,36 +1,42 @@ -import Complex -import System +import Data.Complex +import System.Environment(getArgs) type C = Complex(Double) mandelbrot_eval::Int->C->Int -mandelbrot_eval max_iter c = - length +mandelbrot_eval max_iter c = + length $ (takeWhile (\z -> (magnitude z) < 2)) - $ (take max_iter) + $ (take max_iter) $ (iterate (\z -> z*z+c) (0:+0) ) half_width_pixels::Int -half_width_pixels = 400 +half_width_pixels = 10240 scaling::Double->Int->Double scaling width = (* (width /(fromIntegral half_width_pixels))) . fromIntegral range::Double->[Double] range width= map (scaling width) - [-half_width_pixels .. half_width_pixels] + [1-half_width_pixels .. half_width_pixels] +-- the "28" was discovered by trial and error for zoom 6. iterations::Int -iterations = 200 +iterations = 310+28 -- 310; +-- perl -plwe 'next unless /^\d+$/;if($_>255){$_=255}' fileout | xloadimage stdin +-- perl -plwe 'next unless /^-?\d+$/;if($_>255){$_=255}elsif($_<0){$_=0}' fileout | xloadimage stdin + +truncrange :: Int -> Int +truncrange i = if (i>255) then 255 else if (i<0) then 0 else i; main::IO () main = do{ - let {s = show (2*half_width_pixels+1)}; + let {s = show (2*half_width_pixels)}; putStrLn ("P3\n"++s++" "++s++"\n"++"255"); args <- getArgs; let {side = exp(-(read (head args)))}; - putStr $ unlines $ map show - $ concatMap ( (\i -> [i,i,(i+55)]) + putStr $ unlines $ map (show.truncrange) + $ concatMap ( (\i -> [i-55-28,i-55-28,i-28]) -- (\i -> [i-55,i-55,i]) . (mandelbrot_eval iterations) . (+ center) ) $ [x:+y | x<-(range side), y<-(range side)]