-
Notifications
You must be signed in to change notification settings - Fork 6
/
DelayedMousePositions.elm
36 lines (28 loc) · 1.01 KB
/
DelayedMousePositions.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module DelayedMousePositions where
import Graphics.Element exposing (show)
import List
import List exposing ((::), foldr, length, repeat)
import Mouse
import Signal
import Signal exposing (Signal, (~), (<~), constant)
import Time exposing (delay)
import Window
combine : List (Signal a) -> Signal (List a)
combine = foldr (Signal.map2 (::)) (constant [])
delayedMousePositions : List Int -> Signal (List (Int, (Int, Int)))
delayedMousePositions rs =
let adjust (w, h) (x, y) = (x-w//2,h//2-y)
n = length rs
position = adjust <~ Window.dimensions ~ Mouse.position
positions = repeat n position -- List (Signal (Int, Int))
delayedPositions = -- List (Signal (Int, (Int, Int))
List.map2
(\r pos ->
let delayedPosition = delay (toFloat r*100) pos
in
(\pos -> (r,pos)) <~ delayedPosition)
rs
positions
in
combine delayedPositions
main = show <~ delayedMousePositions [0,10,25]