Published
Edited
Apr 19, 2021
Fork of Matrix Poems
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
poem1 = [["each", "bluebird", "wing", "flapping"],
["weather", "sings", "over", "our"],
["blue", "icy", "sky", "chasm"],
["and", "frost", "colored", "motion"]];
Insert cell
join1 = [[[" ", " "], [" ", " "], [" ", " "], [" ", " "]],
[[" a ", " "], [" with ", " "], [" ", " "], [" ", " "]],
[[" ", " "], [", ", " "], ["-", "-"], ["-", " "]],
[[" ", " "], [" ", "-"], [" ", " "], [" ", " "]]];
Insert cell
Insert cell
Insert cell
function toPoem(text, poempair) {
let poem = poempair[0];
let punc = poempair[1];
let output = "";
if (text.length < 1) {
output = toPoem("something", poempair);
return output;
}
output = poem[0][0];
let binary = toBinary(text);
let row = 0; let col = 0;
let rowMax = poem.length; let colMax = poem[0].length;
for (var i = 0; i < binary.length; i++) {
output += punc[row][col][parseInt(binary[i])];
if (binary[i] === "0") {
row++;
} else {
col++;
}
if (row > rowMax - 1 || col > colMax - 1) {
output += "<br>"
}
row = row % rowMax;
col = col % colMax;
output += poem[row][col];
}
return output;
}
Insert cell
function toTitle(userInput) {
if (userInput === "") {
return "something";
}
return userInput;
}
Insert cell
function toBinary(text) {
let output = "";
let lowText = text.toLowerCase();
for (var i = 0; i < lowText.length; i++) {
output += text[i].charCodeAt(0).toString(2).substring(3,8);
// if (letterMap5.has(lowText[i])) {
// output += letterMap5.get(text.toLowerCase()[i]);
// }
}
return output;
}
Insert cell
Insert cell
Insert cell
Insert cell
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