Skip to content

Instantly share code, notes, and snippets.

@astrieanna
Created September 21, 2014 20:22
Show Gist options
  • Save astrieanna/27c299a390a1273e1cc7 to your computer and use it in GitHub Desktop.
Save astrieanna/27c299a390a1273e1cc7 to your computer and use it in GitHub Desktop.
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