Created
February 24, 2015 17:19
-
-
Save robwhitaker/7fe1bb6719d9891ce9b7 to your computer and use it in GitHub Desktop.
Elm - Basic Form MouseOver Collision
This file contains 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 Graphics.Collage (..) | |
import Graphics.Element (..) | |
import Color (blue) | |
import Text (plainText) | |
import Window | |
import Signal | |
import Mouse | |
main : Signal Element | |
main = Signal.map3 (\x y m -> let | |
mouseCoords = mouseCoordsToFSFormCoords (x,y) m | |
pos = (100,150) | |
r = 100 | |
mouseCollision = circleContainsPoint mouseCoords pos r | |
in collage x y [ move pos <| group [filled blue <| circle r, (toForm (plainText (toString mouseCollision)))] ] | |
) Window.width Window.height Mouse.position | |
mouseCoordsToFSFormCoords : (Int,Int) -> (Int,Int) -> (Int,Int) | |
mouseCoordsToFSFormCoords (winWidth, winHeight) (x,y) = (x - winWidth//2, winHeight//2 - y) | |
circleContainsPoint : (Int,Int) -> (Int,Int) -> Int -> Bool | |
circleContainsPoint (mX,mY) (cX,cY) radius = sqrt(toFloat <| (mX-cX)^2 + (mY-cY)^2) - (toFloat radius) <= 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment