Skip to content

Instantly share code, notes, and snippets.

@gosub
Created September 14, 2014 14:33
Show Gist options
  • Save gosub/6dc782c8e5847f964f00 to your computer and use it in GitHub Desktop.
Save gosub/6dc782c8e5847f964f00 to your computer and use it in GitHub Desktop.
import Window
import Mouse
main = render <~ Window.dimensions ~ allMoves
mousePos =
let nomalize = \(w,h) (x,y) -> (toFloat x - toFloat w / 2, toFloat h / 2 - toFloat y)
in nomalize <~ Window.dimensions ~ Mouse.position
mouseDownAndPos = lift2 (,) Mouse.isDown mousePos
allMoves = foldp inFirstList [[]] mouseDownAndPos
inFirstList (down, (x,y)) (l::ls) =
if down
then ((x, y)::l)::ls
else (if l == []
then l::ls
else ([]::l::ls))
toPath moves = path moves |> traced (solid red)
render (w,h) moves =
collage w h (map toPath moves)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment