summaryrefslogtreecommitdiff
path: root/02.05.hs
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2019-02-27 11:21:56 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2019-02-27 11:21:56 -0500
commit8a4f282eb65af9e74b9c044b5b4558af41b6a107 (patch)
tree81d151e2be2a5f95543f89cd2a7363a7400d2b7b /02.05.hs
parentbdb9f22c1bf5821697561e96bb1913469d160d5f (diff)
downloadsethna.hs-8a4f282eb65af9e74b9c044b5b4558af41b6a107.tar.gz
sethna.hs-8a4f282eb65af9e74b9c044b5b4558af41b6a107.tar.bz2
sethna.hs-8a4f282eb65af9e74b9c044b5b4558af41b6a107.zip
started two problems
Diffstat (limited to '02.05.hs')
-rw-r--r--02.05.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/02.05.hs b/02.05.hs
new file mode 100644
index 0000000..bad7367
--- /dev/null
+++ b/02.05.hs
@@ -0,0 +1,30 @@
+
+import System.Random
+import Control.Monad.State
+import Data.List.Split (chunksOf)
+
+import Graphics.Rendering.Chart.Easy
+import Graphics.Rendering.Chart.Backend.Cairo
+
+import Data.Colour.Names
+import Diagrams.Prelude
+import Diagrams.Backend.SVG.CmdLine
+
+randomWalk :: (RandomGen g) => Int -> Int -> State g [[Double]]
+randomWalk d n = get >>= (\g -> let (g1, g2) = split g in (put g1) >> (return $ take n $ scanl (\x y -> map (uncurry (+)) $ zip x y) (replicate d 0.0) $ chunksOf d $ randomRs (-0.5,0.5) g2))
+
+drawWalk :: [[Double]] -> Diagram B
+drawWalk w = fromVertices $ (\[x, y] -> p2 (x, y)) <$> w
+
+main = do
+ g <- newStdGen
+ let (w10, g2) = runState (randomWalk 2 10) g
+ let (w1000, g3) = runState (randomWalk 2 1000) g2
+ let (w100000, g4) = runState (randomWalk 2 100000) g3
+-- mainWith $ foldr1 Diagrams.Prelude.atop [lc red $ drawWalk w10, lc blue $ drawWalk w1000, lc green $ drawWalk w100000]
+ let (e1, g5) = runState (sequence $ replicate 10000 $ randomWalk 2 2) g4
+ let (e10, g6) = runState (sequence $ replicate 10000 $ randomWalk 2 11) g5
+ mainWith $ foldr1 Diagrams.Prelude.atop [mconcat $ map (place (lw Diagrams.Prelude.none $ fc yellow $ ((circle 0.01) :: Diagram B))) (map (\[x, y] -> p2 (x, y)) (map last e1)), mconcat $ map (place (lw Diagrams.Prelude.none $ fc black $ circle 0.01)) (map (\[x, y] -> p2 (x, y)) (map last e10))]
+
+
+