xxxxxxxxxx
78
let outputP;
let genButton;
function setup() {
noCanvas();
background(255);
textAlign(LEFT, TOP);
textSize(24);
genButton = createButton("Click to generate");
genButton.mousePressed(generate);
outputP = createP("");
}
function draw() {
}
function generate() {
var grammar = tracery.createGrammar(grammarSource);
grammar.addModifiers(tracery.baseEngModifiers);
var output = grammar.flatten("#origin#");
outputP.html(output);
}
// cut and paste your grammar below (as the value for variable "grammarSource")
var grammarSource = {
"origin": "#start.capitalize#, #character# #action#",
"start": [
"When he woke up",
"When she came back",
"When we looked down",
"When they looked up",
"When he came back",
"When she went to sleep",
"When they came back",
"When he opened the door"
],
"character": [
"the dinasour",
"the alien",
"the herd of sheep",
"the starving child",
"the one that survived",
"the Goddess",
"the God",
"the lover",
"the traitor",
"the familiar stranger",
"the soulmate with benefits",
"the real Queen",
"the false Queen",
"the real king",
"the false king",
"the trickster",
"the death",
"the plague"
],
"action": [
"was still there",
"was gone",
"was still looking back",
"was pointing at the sky",
"was still asking the same question",
"was hiding the rest of it",
"was still holding his hand",
"was still holding her hand",
"had taken him away",
"had erased it all",
"had broken the promise",
"had kept the promise",
"had done nothing about it"
]
};