Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lorem Ipsum from Beowulf in Old English
/*
* Modified Lorem Ipsum Generator by Fredrik Bridell (http://bridell.com/loremipsum/)"
*
* To use: download the .js file, and in your html include the markup:
* <script type="text/javascript" src="loremipsum.js"></script>
*
* Where you want the Lorem Ipsum, include something like:
* <script type="text/javascript">loremIpsumParagraph(100)</script>
*/
/* Words from the first two stanzas of Beowulf in Old English. http://www.fordham.edu/halsall/basis/beowulf-oe.asp */
var beowulf =["HWÆT,", "WE", "GAR-DEna", "in", "geardagum,", "þeodcyninga", "þrym", "gefrunon,", "hu", "ða", "æþelingas", "ellen", "fremedon!", "oft", "Scyld", "Scefing", "sceaþena", "þreatum,", "monegum", "mægþum", "meodosetla", "ofteah,", "egsode", "eorlas,", "syððanærest", "wearð", "feasceaft", "funden;", "he", "þæs", "frofre", "gebad,", "weox", "under", "wolcnum", "weorðmyndum", "þah,", "oð", "þæt", "him", "æghwylc", "ymbsittendra", "ofer", "hronrade", "hyran", "scolde,", "gomban", "gyldan;", "þæt", "wæs", "god", "cyning!", "Ðæm", "eafera", "wæs", "æfter", "cenned", "geong", "in", "geardum,", "þone", "God", "sende", "folce", "to", "frofre;", "fyrenðearfe", "ongeat,", "þe", "hie", "ær", "drugon", "aldorlease", "lange", "hwile;", "him", "þæs", "Liffrea,", "wuldres", "Wealdend", "woroldare", "forgeaf,", "Beowulf", "wæs", "breme", "---", "blæd", "wide", "sprang---", "Scyldes", "eafera", "Scedelandum", "in.", "Swa", "sceal", "geong", "guma", "gode", "gewyrcean,", "fromum", "feohgiftumon", "fæder", "bearme,", "þæt", "hine", "on", "ylde", "eft", "gewunigen", "wilgesiþas,", "þonne", "wig", "cume,", "leode", "gelæsten;", "lofdædum", "sceal", "in", "mægþa", "gehwære", "man", "geþeon.", "Him", "ða", "Scyld", "gewat", "to", "gescæphwile", "felahror", "feran", "on", "Frean", "wære;", "hi", "hyne", "þa", "ætbæron", "to", "brimes", "faroðe,", "swæse", "gesiþas,", "swa", "he", "selfa", "bæd,", "þendenwordum", "weold", "wine", "Scyldinga---", "leof", "landfruma", "lange", "ahte.", "Þær", "æt", "hyðe", "stod", "hringedstefna", "isig", "ond", "utfus,", "æþelingesfær;", "aledon", "þa", "leofne", "þeoden,", "beaga", "bryttan", "on", "bearm", "scipes,", "mærne", "be", "mæste.", "Þær", "wæs", "madma", "fela", "of", "feorwegum", "frætwa", "gelæded;", "ne", "hyrde", "ic", "cymlicor", "ceol", "gegyrwan", "hildewæpnum", "ond", "heaðowædum,", "billum", "ond", "byrnum;him", "on", "bearme", "læg", "madma", "mænigo,", "þa", "him", "mid", "scoldon", "on", "flodes", "æht", "feor", "gewitan.", "Nalæs", "hi", "hine", "læssan", "lacum", "teodan,", "þeodgestreonum,", "þon", "þa", "dydon,", "þe", "hine", "æt", "frumsceafte", "forð", "onsendon", "ænne", "ofer", "yðe", "umborwesende"];
// just switch language like this! You can also do this in a script block on the page.
var loremLang = beowulf;
/* Characters to end a sentence with. Repeat for frequencies (i.e. most sentences end in a period) */
var endings = "................................??!";
/* randomly returns true with a certain chance (a percentage) */
function chance(percentage){
return (Math.floor(Math.random() * 100) < percentage);
}
/* capitalizes a word */
function capitalize(aString){
return aString.substring(0,1).toUpperCase() + aString.substring(1, aString.length);
}
/* returns a random lorem word */
function getLoremWord(){
return loremLang[Math.floor(Math.random()*loremLang.length)];
}
function getLoremEnding(){
var i = Math.floor(Math.random()*endings.length);
return endings.substring(i, i+1);
}
/* inserts a number of lorem words. Does not append a space at the end. */
function loremIpsum(numWords){
for(var i=0; i<numWords-1; i++){
document.write(getLoremWord() + " ");
}
document.write(getLoremWord());
}
/* inserts a sentence of random words. Appends a space at the end. */
function loremIpsumSentence(numWords){
document.write(capitalize(getLoremWord()) + " ");
loremIpsum(numWords-1);
document.write(getLoremEnding());
document.write(" ");
}
/* inserts a sentence of random words, sometimes with extra punctuation. Appends a space at the end. */
function loremIpsumSentence2(numWords){
document.write(capitalize(getLoremWord()) + " ");
var part1 = 0;
if(chance(50)){
// insert a comma or other punctuation within the sentence
part1 = Math.floor(Math.random() * numWords-2);
loremIpsum(part1);
document.write(", ");
} else {
document.write(" ");
}
loremIpsum(numWords - part1 - 1);
document.write(getLoremEnding());
document.write(" ");
}
/* inserts a paragraph of sentences of random words. */
function loremIpsumParagraph(numWords){
var words = numWords;
while(words > 0){
if(words > 10){
w = Math.floor(Math.random() * 8) + 2;
loremIpsumSentence2(w);
words = words - w;
} else {
loremIpsumSentence2(words);
words = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment