Public
Edited
Feb 15
Insert cell
Insert cell
Insert cell
Insert cell
playembedded = play()
Insert cell
play = async () => {
// for (let i = 0; i < 2; i++) {
// yield "reading";
let playMp3 = false;
for (let score in scores) {
let theScore = scores[score];
for (let unit = 0; unit < theScore.length; unit++) {
if (trailingFades > 0 && unit == trailingFades) {
playScore(theScore);
if (playMp3) {
playMp3 = false;
Promises.delay(1600).then(() => playRecording());
}
}
await scorepause(theScore[unit].pause * factor, theScore[unit].id);
// console.log(`index: ${i}`);
}
}
// recording.currentTime = 0;
// yield "read";
// }
}
Insert cell
factor = 1
Insert cell
playRecording = function() {
let recording = document.createElement('audio');
recording.src = recordingMp3;
recording.play();
}
Insert cell
recordingMp3 = await FileAttachment("whilewishing.mp3").url()
Insert cell
playScore = async function(theScore) {
for (let unit = 0; unit < theScore.length; unit++) {
await scorepause(theScore[unit].pause * factor, theScore[unit].id);
}
}
Insert cell
Insert cell
scorepause = (pause, id) => {
return Promises.delay(pause * 1000).then(() => {
let theElem = document.getElementById(`${id}`);
theElem.classList.toggle('visible');
});
}
Insert cell
scores = [readThrough]
Insert cell
spans = {
let spanString = "",
spaceIfNoHyphen = " ";
let i = 0;
alignedWords.forEach((wordObj, index) => {
let word = wordObj['word'].trim();
let offl = fixedOffsets[index][0];
let offt = fixedOffsets[index][1];
spanString += `<span id='u${i++}' class='text' style='left:${offl}vw;top:${offt}vw'>${word}</span>${spaceIfNoHyphen}`;
});
return spanString;
}
Insert cell
Insert cell
trailingFades = 13 // was 5
Insert cell
alignedWords = alignWords(alignWords_rawJSON)
Insert cell
RiTa = require("rita@2")
Insert cell
Insert cell
alignWords_rawJSON = FileAttachment("whilewishing_raw@2.json").json()
Insert cell
alignWords_lineated = FileAttachment("whilewishing_lineated.json").json()
Insert cell
alignWords_versed = FileAttachment("whilewishing_versed.json").json()
Insert cell
transitionTime = 2
Insert cell
Insert cell
Insert cell
Insert cell
verseSpanned = html`${addSpansTo(verseText)}`
Insert cell
fixedOffsets = wordOffsets(verseSpanned)
Insert cell
wordOffsets = verseSpans => {
let array = [];
if (verseSpans == ``) return array;
let nodes = Array.from(verseSpans.children);
let initialTopOffset = null;
let differenceSoFar = 0;
nodes.forEach((node, index) => {
if (node.offsetLeft != undefined) {
// safety only
if (initialTopOffset === null) initialTopOffset = node.offsetTop;
if (node.innerHTML.indexOf("<stanza>") != -1) {
// currentTopOffset = initialTopOffset;
differenceSoFar = node.offsetTop + node.offsetHeight;
return;
}
array.push([
pxToVw(node.offsetLeft),
pxToVw(initialTopOffset + (node.offsetTop - differenceSoFar))
]);
}
});
return array;
}
Insert cell
function pxToVw(px) {
return px * (100 / document.documentElement.clientWidth);
}
Insert cell
min_height = 480;
Insert cell
Insert cell
import { LAOB, laob_notebook_css } from "@laob/imports"
Insert cell
laob_notebook_css
Insert cell
css = html`
<style>

.verse {
position: relative;
cursor: none;
min-height: ${min_height}px;
font-family: Perptua, serif;
font-size: 3.5vw;
line-height: 1.1;
}

.text {
position: absolute;
color: rgba(0,0,0,0);
transition: color ${transitionTime}s ease-in-out;
}

.text.visible {
color: rgba(0,0,0,255);
}

</style>
`
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more