module Graphics.Mars.Graph where
import Prelude
((+), (*), fromIntegral, round, Float, Int, take, IO, map,
(), return, sequence, max, (/=), error, zip)
import Data.Array.IO (newArray, IOUArray, freeze)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (elems, bounds, listArray)
import Graphics.Mars.Stamp
import Graphics.Mars.Walk
import System.Random (mkStdGen)
import Control.Monad.Random (getRandomR, evalRand)
graph
:: Int
-> Int
-> Float
-> Float
-> Int
-> Int
-> Float
-> (Float, Float)
-> IO (UArray (Int, Int) Float)
graph height width radius walkfactor seed iterations scalefactor sp
= do a <- (newArray ((0, 0), (height, width)) 0.0 :: IO (IOUArray (Int, Int) Float))
stampL a (circleStamp (radius * scalefactor) :: UArray (Int, Int) Float)
(take iterations
[ (round (f1 + (fromIntegral height) * 0.5), round (f2 + (fromIntegral width) * 0.5))
| (f1, f2) <- walk walkfactor sp (mkStdGen seed) ])
freeze a
zRandomize :: Float
-> Int
-> UArray (Int, Int) Float
-> UArray (Int, Int) Float
zRandomize delta seed a =
listArray (bounds a)
(evalRand m (mkStdGen seed))
where m = sequence (map f (elems a))
f e = do r <- getRandomR ((0 delta), delta)
return (e + r)
meldGraphs :: UArray (Int, Int) Float
-> UArray (Int, Int) Float
-> UArray (Int, Int) Float
meldGraphs a1 a2 =
if bounds a1 /= bounds a2
then error "UArray bounds must be equal"
else listArray (bounds a1)
(map (\(x, y) -> max x y) (zip (elems a1) (elems a2)))