Published
Edited
Apr 5, 2021
Insert cell
md`# P r e s e n t a t i o n -- with Dictionary`
Insert cell
display = html`<div class = 'textcontainer'> ${mutableTxt[0].replace(/-g/g, " <br> ")}</div>`
Insert cell
ticker = {
while (true) {
yield await Promises.tick(getRandomInt(500,700)).then(() => {
mutableTxt[0] = update(generateWordArrays(poem1));
display.innerText = mutableTxt[0].replace(/-g/g, " \n ");
});
}
}
Insert cell
update = function(lPoem) {
let words = RiTa.tokenize(mutableTxt[0]); // split into words

// loop a random number of times: 1 - numberOfPossibleReplacements
//loop from random spot
let r = Math.floor(Math.random() * words.length);
//for (let i = r; i < words.length + r; i++) {
//let idx = i % words.length;
let idx = r % words.length;
words[idx] = randomWord(lPoem[idx], words[idx]);
//}
return RiTa.untokenize(words);
// mutable txt = RiTa.untokenize(words); // actually even with await Promises ... this does not work
// mutableTxt[0] = RiTa.untokenize(words); // this would also work
}
Insert cell
function randomWord(wordArray, currentWord) {
// only works with flat arrays of words
let safetyCounter = 0,
word;
do {
word = wordArray[randInt(wordArray.length)];
} while (
currentWord != undefined &&
word == currentWord &&
safetyCounter++ < 100
);
return word;
}
Insert cell
randInt = maxPlusOne => (maxPlusOne * Math.random()) | 0
Insert cell
/*(newpulse, rs`
<h1> Dear darkskins </h1>

( imagine if <br> you didn't | you don't )
have to earn
it all
`)*/
Insert cell
function generateWordArrays(words1){
let fullPoem = [];
for(let ii = 0; ii < words1.length; ii++){
fullPoem[ii] = Array(
words1[ii],
Dictionary[words1[ii]].gibberishWord,
Dictionary[words1[ii]].userSynonym
);
}
return fullPoem;
}
Insert cell
function hi(){
return Dictionary[replacementWords[1]].gibberishWord;
}
Insert cell
x = hi();
Insert cell
import { andaleMono } from "@shadoof/sifther"
Insert cell
css = html`
<style>

@font-face {
font-family: 'AndaleMono';
src: url('${await andaleMono.url()}');
}

.textcontainer {
position: relative;
min-height: 270px;
font-family: 'AndaleMono', monospace;
font-size: 3vw;
}

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

.text.visible {
color: rgba(0,0,0,255);
/* starts readable */
}

</style>
`
Insert cell
function genDict(){
let dict = new Map();
for (let i=0; i<replacementWords.length; i++){
dict[replacementWords[i]] = {gibberishWord: generateGibberish(replacementWords[i]), userSynonym: userSynonyms[i]};
}
dict["-g"] = {gibberishWord: "-g", userSynonym: "-g"};
return dict;
}
Insert cell
mutableTxt = ["our early melting -g we slow our tongues -g and breathe others -g palms unfurl -g carve bodies"];
Insert cell
poem1 = RiTa.tokenize("our early melting -g we slow our tongues -g and breathe others -g palms unfurl -g carve bodies");
Insert cell
Dictionary = genDict();
Insert cell
replacementWords = ["the", "new", "cracked", "we", "and", "freeze", "backs", "carve", "our", "clasped", "palms", "slow", "melting", "breathe", "early", "unfurl", "molds", "bodies", "them", "seeds", "their", "tongues", "others"];
Insert cell
userSynonyms = ["the", "fallen", "upset", "they", "and", "live", "necks", "loop", "their", "stolen", "finger", "lost", "crouching", "sing", "blue", "leap", "cats", "animals", "them", "books", "their", "boots", "houses"];
Insert cell
largePoem = generateWordArrays(poem1);
Insert cell
vowels = ["a", "e", "i", "o", "u", "oo", "eu", "ae"];
Insert cell
Insert cell
//Creating new Gibberish Words based of number of syllabels in input word
function generateGibberish(oWord){
let syllables = RiTa.syllables(oWord);
let syllablesArray = syllables.split('/');
var numSyllables = syllablesArray.length;
var gibberish = "";
var notOneVowel = (oWord.length > 1 && numSyllables == 1);
//stuff about contractions
/*if has Prefix
if ending of prefix = vowel --> start root word with consonant
else --> start root word with vowel
if has suffix
if beginning of suffix = vowel --> end root word with consonant
else --> end root word with vowel
*/

let rand = Math.random();
//What word starts with
if (rand <0.3){
var startVowel = true;
} else {
var startVowel = false;
}
for (let j=0; j<numSyllables; j++){ //loop for number of syllables
//Syllable starts w/ Vowels
if (startVowel == true) {
gibberish += createVowel(notOneVowel);
}
else {
gibberish += createConsonant();
}
if(consonants.indexOf(gibberish.slice(-1)) > 0){
startVowel = true;
}
else{
startVowel = false;
}
}
//if gibberish == real word --> create new gibberish word
return gibberish;
}
Insert cell
//Create a single syllable starting with a vowel:
function createVowel(notOneVowel){
let newVowel = vowels[getRandomInt(0, vowels.length)]; //random starting vowel
let numLetters = getRandomInt(1, 3); //generate random number for either 1 or 2 letter syllable
if (notOneVowel === true){
numLetters = 2;//if one syllable word with more than 1 letter
} //don't allow gibberish to be 1 vowel
if (numLetters > 1){ //if syllable has more than 1 letter
newVowel += consonants[getRandomInt(0, consonants.length)]; //add a random consonant
}
return newVowel;
}
Insert cell
//Create a single syllable starting with a consonant
function createConsonant(){
let newConsonant = consonants[getRandomInt(0, consonants.length)] + vowels[getRandomInt(0, vowels.length)]; //random starting consonant and random addition vowel
let numLetters = getRandomInt(2, 4); // random length 2-3
if(numLetters > 2){ //if syllable 3 letters
newConsonant += consonants[getRandomInt(0, consonants.length)]; //add consonant
}
return newConsonant;
}
Insert cell
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
Insert cell
RiTa = require("rita")
Insert cell
RiTa.VERSION
Insert cell
import {rs} from "@dla/imports"
Insert cell
import {pulse} from "@dla/imports"
Insert cell
newpulse = pulse(1200)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more