Learning Tracery
Tracery is a “story-grammar generation library” written in JavaScript. It was created by Kate Compton and has risen in popularity for its easy-to-follow functions for taking a set of options and creating a grammar that can produce different texts.
Example
Play with the example on Repl.It!
Definitions
While Tracery may seem complicated at first, it works on two things: symbols and rules.
Symbols
Think of symbols as possible outcomes. These can be words, numbers, or phrases. They are simply possible output.
Rules
Rules are just that: rules. The rules define how the symbols relate to each other.
Symbols + Rules = Grammar
In Tracery, symbols are given to it through the createGrammar() function. They define what the symbols are and possible values for those symbols to create a grammar.
Then, with the rules and symbols, the grammar is flattened into one possible outcome through filtering the symbols, their possibilities, and the rules.