Skip to content

Instantly share code, notes, and snippets.

@samplereality
Created February 11, 2015 11:51
Show Gist options
  • Save samplereality/d4ec9b3184956afce74a to your computer and use it in GitHub Desktop.
Save samplereality/d4ec9b3184956afce74a to your computer and use it in GitHub Desktop.
Moby Dick in Markov Chains
<html>
<head>
<canvas id="canvas" width=1200 height=400 style="border: 0px dashed #000000; display: block; margin:0 auto;"></canvas>
<script src="rita.js"></script>
<script>
RiTa.p5Compatible(true);
RiText.defaultFont("Georgia",18);
var rm = new RiMarkov(RiTa.random(2,5));
rm.minSentenceLength = 2;
rm.maxSentenceLength = 15;
RiTa.loadString('moby-dick.txt', function(text) {
rm.loadText(text);
var sentenceOne = rm.generateSentences(1);
var sentenceTwo = rm.generateSentences(1);
var output = sentenceOne + " " + sentenceTwo + " (" + rm.getN().toFixed(0) + "-gram)";
console.log(rm.getN());
RiText(output).draw();
});
</script>
</head>
<body>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment