Week 12 - Procedural Text Generation

Date: 2025-04-22

Markov

In the hands of metereologists, ecologists, computer scientists, financial engineers and other people who need to model big phenomena, Markov chains can get to be quite large and powerful. For example, the algorithm Google uses to determine the order of search results, called PageRank, is a type of Markov chain. –Victor Powell and Dr. Lewis Lehe, setosa.io

Note: take a look at the comments (don’t make me regret this!) to see some complaints from people about the use of Markov text generation.

Yeah, it is funny and all, but it totally ruins immersion. For some players it isn`t a big deal: some are playing for “intellectual challenge”, some just having fun with procedural stuff, but lots of players care very much about overall consistency and atmosphere.. This feature would ruin game for them.

RiTA library for working with Markov

RiTa library in Javascript for natural language processing tools including Markov chain text generation. Works with p5.js.

5 Card Nancy

A dadaist card game using panels from Ernie Bushmiller’s 20th Century comic strip Nancy.–Scott McCloud

image from Austin Kleon, original Nancy panels by Ernie Bushmiller

5 Card Nancy from 741.5 Comics via the Wayback Machine

Generative Text

Tracery is a generative grammar system / text replacement tool created by scholar Kate Compton. It is a javascript-based library where text expands with filled-in replacement words, and also includes affordances such as capitalization, a/an, and the like.

There is a bit of a bug when trying to integrate with p5.js and Tracery in the web editor as p5 delays the loading ofTracery. To counter this, we add a button to run our tracery generator. Alternatively, you can build in a delay to run tracery after p5 loads.

<html lang="en">
<head>
 <title>My Tracery and p5.js project</title>
 
   <script src="p5.min.js">
   <!-- tracery requires jquery. i'm using jquery slim -->
   <script src="jquery.js"></script>
   <!-- import tracery -->
   <script src="tracery.min.js"></script>
   <meta charset="utf-8">
</head>
<body>
   <script src="script.js"></script>
</body>
</html>

starter code:

//Lee Tusman 2025 CC BY NC SA

const ourText = {
  greeting: [
    "Hello!",
    "Top of the morning to ya!",
    "The best part of waking up is Folger's in your cup,",
  ],
  person: ["stranger", "sailor", "mom"],
  occurrence: ["talking to a #person#"],
  origin: [
    "#greeting# #person.capitalize#. I couldn't help but notice you #occurrence#.",
  ],
};
function setup(){
   noCanvas();
   btn = createButton("Generate");
   btn.mousePressed(gen);
}

function gen() {
  //starts up Tracery
  let grammar = tracery.createGrammar(ourText);
  //saves output as a string
  let s = grammar.flatten("#origin#");

  //create a paragraph
  let p = document.createElement('p');
  //add to page
  document.body.appendChild(p);
  //change text to our generated text
  p.innerHTML = s;
}

Resources

Read

Ethical Procedural Generation - Mike Cook, from Procedural Generation in Game Design

Try Cook’s A Long Walk

Play a game that makes significant use of procedural generation

Recommendations:

Reigns - A free online or iOS/Android game. Flip through cards to make decisions and see how your games turns out playing as a king or queen of a rough middle ages empire.

Games from Michael Brough such as Zaga-88, 868-Hack or P1 Select - online at smestorp.com or on iOS, for download and on iOS. These small grid games are procedurally generated abstract puzzle games. Free or a few bucks.

A Long Walk - short experience, very simple but beautiful (i think), about walking past dedicated benches on a pier. Also see other games by Cook.

Dwarf Fortress - Both free and commercial versions available. Difficult to get started though new tutorials help. This is considered the largest procedurally generated worlds in any game, though has ‘simple’ 2d top down graphics.

Caves of Qud - a similar style of game. A generated world of mutants and broken technologies and the ruins of civilizations. 2d ‘simple’ top down graphics.

Hades - commercial game, contemporary style procedurally generated RPG battles

Signs of the Sojourner - Commercial game but really cool procedurally generated magical realist story. Playing an alternate version of Dominos/matching game changes the story as the game progresses.

Homework: Propose

Your final project is a project that makes use of procedural generation. It can be a procedurally-generated game, story, art toy or other digital media.

It is permitted to include ‘hand-crafted’ content as well as procedurally-generated content.

The final project should be a compelling work that is complete on its own and produces different meaningful results each time it is run.

Write a proposal for your final project. Includes screenshots of other media that has influenced your thinking, and any thoughts, techniques for building, or questions that you have at this time.

High level idea: You are worldbuilding, creating an ecosystem of characters, a world with varied terrain or environment, and procedurally generated objects in that world and text.

Suggested Default Deliverables (If you have an alternate idea such as procedurally-generated book, movie, etc, let me know):

Optional: * procedurally generated music

EXAMPLE ARTWORKS

Artworks with Procedural Generation

Loren Schmidt

Andy Wallace

ArtAtomic

Cory Green

Morikana

Ian MacLarty

Spencer Change