Created
June 1, 2013 14:31
-
-
Save dcalacci/5690598 to your computer and use it in GitHub Desktop.
animated ball moves to last clicked location
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 Either | |
import Mouse | |
import Window | |
-- updates for movement | |
data Update = Click (Int,Int) | TimeDelta Time | |
-- control | |
input = let clickPos = sampleOn Mouse.clicks Mouse.position | |
in merge (Click <~ clickPos) | |
(TimeDelta <~ (40 `fpsWhen` (second `since` clickPos))) | |
-- steps | |
step inp ((tx,ty),(x,y)) = | |
case inp of | |
Click t -> (t, (x,y)) | |
TimeDelta d -> ((tx,ty), ( x + (tx-x) * (d/100) , | |
y + (ty-y) * (d/100) )) | |
-- MODEL | |
data Update = Click (Int,Int) | TimeDelta Time | |
-- view | |
ball (w,h) (endpos,(x,y)) = | |
collage w h [ circle 10 |> filled blue | |
|> move (x- toFloat w/2, toFloat h/2-y) ] | |
main = ball <~ Window.dimensions | |
~ foldp step ((0,0),(0,0)) input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment