Last active
March 28, 2016 13:39
-
-
Save dela3499/e293041aaa1f5f3f77af to your computer and use it in GitHub Desktop.
Show progress of song as its played.
This file contains hidden or 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 Time exposing (Time) | |
import Graphics.Element exposing (show, image) | |
import Graphics.Collage exposing (collage, path, solid, traced, defaultLine, toForm, move) | |
import Signal | |
import Window | |
import Color exposing (..) | |
import String | |
duration = 60 * 5 | |
multiplier = 0.95 | |
offset = 0.03 | |
--main = Signal.map2 view Window.dimensions (Time.every 200) | |
main = Signal.map2 view fractionSoFar Window.dimensions | |
timeSoFar : Signal Time | |
timeSoFar = | |
Signal.foldp (\x y -> y + 0.01) 0 (Time.every 10) | |
fractionSoFar: Signal Time | |
fractionSoFar = Signal.map (\a -> a / duration) timeSoFar | |
view fraction (w, h) = | |
let w' = toFloat(w) | |
h' = toFloat(h) | |
x = -w'/2 + w' * fraction * multiplier + (offset * w') | |
line = path [(x,-h'/2),(x,h'/2)] |> traced s | |
sec = (round (duration * fraction)) | |
in collage w h | |
[ image w (floor (w' / 4.76)) "http://i.imgur.com/v5LzpgD.png" |> toForm | |
, line | |
, show (printsec sec) |> toForm |> move (x + 30,200)] | |
s = { defaultLine | |
| width = 4 | |
, color = red} | |
printsec s = | |
let min = floor ((toFloat s) / 60) | |
sec = toString (s - (min * 60)) | |
padding = if (String.length sec) < 2 then "0" else "" | |
in (toString min) ++ ":" ++ padding ++ sec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment