Last active
October 13, 2015 03:47
-
-
Save nodename/4134192 to your computer and use it in GitHub Desktop.
This Elm program compiles to a Web page that plays a movie of image files, reversing direction when it reaches the last or first image
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 Time (every) | |
import Window (dimensions) | |
firstImageIndex = 0 | |
lastImageIndex = 1000 | |
delta = lift inSeconds (fps 30) | |
modCount signal period = lift (\a -> a `mod` period) (count signal) | |
data PlayDirection = Fwd | Back | |
yoyoIndex direction fwdIndex reverseIndex = if (direction == Fwd) then fwdIndex else reverseIndex | |
yoyo signal period = | |
let fwdIndices = modCount signal period | |
reverseIndices = lift (\a -> period - a) fwdIndices | |
turnarounds = keepIf (\a -> a == 0) false fwdIndices | |
directions = (lift (\t -> if (t `mod` 2 == 0) then Fwd else Back) (count turnarounds)) | |
in | |
lift3 yoyoIndex directions fwdIndices reverseIndices | |
showSlide (w,h) imageIndex = | |
let filename = "morph/" ++ show imageIndex ++ ".svg" | |
pic = image 800 800 filename | |
textElement = text (Text.color white (toText $ show imageIndex)) | |
in | |
color black . container w h middle $ flow down [ container w (heightOf pic) middle pic, container w 100 midTop textElement ] | |
showSlides first last interval = lift2 showSlide dimensions (lift (\a -> a + first) (yoyo (every interval) (last - first))) | |
main = showSlides firstImageIndex lastImageIndex delta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment