Created
April 29, 2019 14:24
-
-
Save nrdmn/c5eece6d7ad467e306a6756fa88ace87 to your computer and use it in GitHub Desktop.
mandelbrot.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Complex | |
import Data.List | |
import Control.Parallel.Strategies | |
mandelbrot c = c : [z^2 + c | z <- mandelbrot c] | |
color (a,b,c,d) x y | |
| len < a = ' ' | |
| len < b = '.' | |
| len < c = ':' | |
| len < d = '+' | |
| otherwise = '#' | |
where len = length $ take d $ takeWhile ((< 2) . magnitude) $ mandelbrot (x :+ y) | |
--grid f x y = [[f x y | x <- x] | y <- y] | |
grid f x y = parMap rdeepseq (\y -> [f x y | x <- x]) y | |
draw c (x,y) step = unlines $ grid (color c) xs ys | |
where xs = [(x-60*step),(x-59*step)..(x+59*step)] | |
ys = [(y-30*step*scaling),(y-29*step*scaling)..(y+29*step*scaling)] | |
scaling = 1.25 | |
views = [ | |
((3,10,20,40), (-0.6, 0), 0.025) | |
, ((7,12,25,50), (-0.57, -0.4), 0.014) | |
, ((10,15,30,60), (-0.54459985, -0.45), 0.008) | |
, ((12,20,40,80), (-0.54459985, -0.49), 0.005) | |
, ((18,25,50,100), (-0.54459985, -0.49), 0.002) | |
, ((25,30,60,110), (-0.54459985, -0.49), 0.001) | |
, ((35,50,70,120), (-0.54459985, -0.495), 0.0005) | |
, ((40,65,80,130), (-0.54459985, -0.4995), 0.00025) | |
, ((60,80,100,150), (-0.54459985, -0.4995), 0.00014) | |
, ((90,110,140,180), (-0.54459985, -0.4999), 0.00006) | |
, ((100,130,160,200), (-0.54459985, -0.49994905), 0.00002) | |
, ((110,140,180,220), (-0.54459985, -0.49994905), 0.00001) | |
, ((110,150,180,220), (-0.54459985, -0.49994905), 0.000005) | |
, ((120,160,200,240), (-0.54459985, -0.49994905), 0.000002) | |
, ((120,160,200,240), (-0.54459985, -0.49994905), 0.000001) | |
, ((120,160,200,240), (-0.54459985, -0.49994905), 0.0000005) | |
, ((120,160,200,240), (-0.54459985, -0.49994905), 0.0000002) | |
, ((120,160,200,240), (-0.54459985, -0.49994905), 0.0000001) | |
, ((130,160,200,240), (-0.54459985, -0.49994905), 0.00000005) | |
, ((140,180,220,240), (-0.54459985, -0.49994905), 0.00000002) | |
, ((160,180,230,260), (-0.54459985, -0.49994905), 0.00000001) | |
, ((190,220,260,300), (-0.54459985, -0.49994905), 0.000000005) | |
, ((240,270,300,350), (-0.54459985, -0.49994905), 0.000000002) | |
, ((290,320,350,400), (-0.54459985, -0.49994905), 0.000000001) | |
, ((325,340,380,410), (-0.54459985, -0.49994905), 0.0000000005) | |
, ((345,360,390,420), (-0.54459985, -0.49994905), 0.0000000002) | |
, ((360,380,400,440), (-0.54459985, -0.49994905), 0.0000000001) | |
, ((375,390,420,460), (-0.54459985, -0.49994905), 0.00000000005) | |
, ((390,420,440,490), (-0.54459985, -0.49994905), 0.00000000002) | |
, ((410,430,480,510), (-0.54459985, -0.49994905), 0.00000000001) | |
, ((430,450,500,530), (-0.54459985, -0.49994905), 0.000000000005) | |
, ((440,480,520,550), (-0.54459985, -0.49994905), 0.000000000002) | |
, ((460,490,530,570), (-0.54459985, -0.49994905), 0.000000000001) | |
] | |
main = putStrLn $ concat $ intersperse (replicate 120 '=' ++ "\n") $ uncurry3 draw <$> views | |
where uncurry3 f (a,b,c) = f a b c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment