Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.