Skip to content

Instantly share code, notes, and snippets.

@samrat
Last active August 29, 2015 14:03
Show Gist options
  • Save samrat/d48f14ecf2ea00e1582c to your computer and use it in GitHub Desktop.
Save samrat/d48f14ecf2ea00e1582c to your computer and use it in GitHub Desktop.
Random walk with "leaps"
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