Skip to content

Instantly share code, notes, and snippets.

@jamesmacaulay
Created October 10, 2014 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmacaulay/bbfb662b068e8a4e8d60 to your computer and use it in GitHub Desktop.
Save jamesmacaulay/bbfb662b068e8a4e8d60 to your computer and use it in GitHub Desktop.
import Mouse
import Array
buildAppDataMap delta pos history =
{ frameDelta=delta
, mousePosition=pos
, clickHistory=history }
arrayTakeLast n array =
let inputLen = Array.length array
outputLen = min inputLen n
in Array.slice (inputLen - outputLen) inputLen array
addToHistory pos hist =
arrayTakeLast 4 (Array.push pos hist)
clickHistory = Mouse.position
|> sampleOn Mouse.clicks
|> foldp addToHistory Array.empty
appData = buildAppDataMap <~ (fps 25) ~ Mouse.position ~ clickHistory
main = lift asText appData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment