Last active
August 29, 2015 14:03
-
-
Save samrat/d48f14ecf2ea00e1582c to your computer and use it in GitHub Desktop.
Random walk with "leaps"
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 Random | |
(w,h) = (600, 400) | |
initialPosition = (0, 0) | |
step2 seed = | |
let floats = Random.floatList (always 4 <~ seed) | |
randCoords [f1,f2,f3,f4] = | |
let s = if f1 < 0.01 then 50 else 1 | |
n = if f2 < 0.5 then s else -s | |
scaleFloat f = f * n | |
in (scaleFloat f3, scaleFloat f4) | |
in lift randCoords floats | |
translate (x, y) (dx, dy) = (x+dx, y+dy) | |
walk = foldp (\delta acc -> (translate (head acc) delta) :: acc) | |
[initialPosition] | |
(step2 (fps 30)) | |
draw p = collage w h | |
[ traced (solid lightBlue) <| path p ] | |
main = lift draw walk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment