Last active
January 30, 2017 16:27
-
-
Save oswaldo/0fe6bb55e56c3c918b4ab8780a512e93 to your computer and use it in GitHub Desktop.
Simple ScalaJS "Speed Reader" example
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
//https://scalafiddle.io/sf/55sE0OL/10 | |
import scalatags.JsDom.all._ | |
import org.scalajs.dom | |
import fiddle.Fiddle.panel | |
val wpm = 300d | |
val group = 1 | |
val interval = 60 / wpm * group * 1000 | |
val message = """Speed reading is any of several techniques used to improve one's ability to read quickly. | |
Speed reading methods include chunking and minimizing subvocalization. | |
The many available speed reading training programs include books, videos, software, and seminars.""" | |
val tokens = message.split("\\s+").grouped(group).map(_.mkString(" ")).toList ++ List("") | |
def start(again: Boolean = false): Unit = println(button((if (again) "Restart" else "Start"), onclick := { () => | |
var i = 0 | |
var intervalHandle = 0 | |
intervalHandle = dom.window.setInterval(() => { | |
while (panel.childElementCount > 0) | |
panel.removeChild(panel.firstChild) | |
if (i < tokens.size) { | |
panel.appendChild( | |
div( | |
padding := "10px", | |
id := "page", | |
h1( | |
margin := "auto", | |
textAlign := "center", | |
tokens(i))).render) | |
i = i + 1 | |
} else { | |
dom.window.clearInterval(intervalHandle) | |
start(again = true) | |
} | |
}, interval) | |
})) | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated to current scalafiddle.io