Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
modified version of http://elm-lang.org/edit/examples/Elements/Lines.elm (the red square follows the mouse)
import Mouse
# Separating main and squares was key to making lift work
# I don't know how to convert Signal (Int,Int) to Signal (Float,Float)
# so I separated x and y into different arguments
main = lift2 squares (toFloat <~ Mouse.x)
(toFloat <~ Mouse.y)
squares : Float -> Float -> Element
squares x y =
collage 500 500
[ move (0,0) blueSquare
, move (x - 250,250 - y) redSquare
]
blueSquare : Form
blueSquare = traced (dashed blue) square
redSquare : Form
redSquare = traced (solid red) square
square : Path
square = path [ (50,50), (50,-50), (-50,-50), (-50,50), (50,50) ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment