-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerialMandelbrot.hs
39 lines (30 loc) · 1.18 KB
/
SerialMandelbrot.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--SerialMandelbrot.hs
--Author Justin Dawson ([email protected])
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Graphics.Blank
import qualified Data.Vector.Unboxed as V
import Data.Complex
import qualified Data.Text as Text
import Control.Monad
import Debug.Trace
import GHC.Word
import Data.Time
step= 0.00125
mandelbrot :: Double -> Double -> [Word8]
mandelbrot x y = let val = x :+ y
zs = take 255 $ iterate (\z -> z^2 + val) 0
iter = fromIntegral $ length $ takeWhile (\intermediate -> magnitude intermediate < 2) zs
in [iter,0,iter,255]
main:: IO()
main = blankCanvas 3000 {middleware=[]}$ \ context -> do
putStrLn "Start Request"
start <- getCurrentTime
let v = [(x,y)| y<-[1,(1-step) .. -1], x <-[-2, (-2 + step) .. 0.5]]
let res = map (\(x,y)->mandelbrot x y) $ v
send context $ do let w = ((abs . round) $ (0.5 - (-2)) / step) + 1
let h = ((abs . round) $ ((-1) -1) / step) + 1
putImageData (ImageData (fromIntegral w) (fromIntegral h) (V.fromList (concat res)), [0,0])
stop <- getCurrentTime
print $ diffUTCTime stop start
putStrLn "Finished"