Skip to content

Instantly share code, notes, and snippets.

@joshy
Created December 23, 2014 13:29
Show Gist options
  • Save joshy/dd86752f60ec6c9e0297 to your computer and use it in GitHub Desktop.
Save joshy/dd86752f60ec6c9e0297 to your computer and use it in GitHub Desktop.
import Graphics.Element (..)
import Signal (Signal, map, map2, sampleOn)
import Mouse
import Text (asText)
import Window
main : Signal Element
main = map asText mousePos
mouseClickPos : Signal (Int, Int)
mouseClickPos = sampleOn Mouse.clicks Mouse.position
mousePos : Signal Point
mousePos = map2 convert mouseClickPos Window.dimensions
convert : (Int, Int) -> (Int, Int) -> Point
convert (x,y) (w,h) =
{x = (toFloat x - (toFloat w/2)), y = ((toFloat h/2) - toFloat y) }
type alias Point = {x:Float, y:Float}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment