xxxxxxxxxx
70
let outputP;
function setup() {
noCanvas();
background(255);
textAlign(LEFT, TOP);
textSize(50);
outputP = createP("Click to generate");
}
function draw() {
}
function mousePressed() {
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")
/*
Long times ago there is an old man named Sai Weng lives near by the great wall.
One day, he loses a great horse. His neighbors and relatives hear the news and come over to comfort him.
However, He is not anxious about it.
He laughs and says: "The horse is lost. How does anyone know if this is a not good thing?"
After a few months pass, Sai Weng's horse returns to his home. Also brings another great horse back with it.
This news surprised everyone in the village, and everyone congratulates him.
But Sai Weng is not so happy about it. He says to everyone: "There is nothing to celebrate.
Who can say this is not a possible disaster?"
After a few days, Sai Weng's only son wants to ride the wild horse.
The wild horse refuses and kicks his son off of him. The son falls and breaks his leg.
Everyone hears the news, and comes over to comfort him.
Sai Weng is not sad about the event, he says: "Maybe this is a good thing."
During his son's recovery, a war breaks out at the border.
Young men of the village are drafted into the army.
Most of them die on the frontline, but Sai Weng's son is alive, because his broken leg.
*/
var grammarSource ={
"origin": "#[#setHero#][#setBadEvent#]story#",
"setHero": [
"[hero:Garfield][heroDesc:a large cat][conveyance:magic lasagna pan]",
"[hero:Harry Potter][heroDesc:a famous Gryffindor][conveyance:broomstick]",
"[hero:some guy][heroDesc:a guy I know][conveyance:rusty Toyota Corolla]"
],
"setBadEvent": [
"[needBadReason:an illness][solutionAction:heals]",
"[needBadReason:a great poverty][solutionAction:enriches]",
"[needBadReason:an ancient Egyptian curse][solutionAction:lifts the curse from]"
],
"setGoodEvent": [
"[needGoodReason:found a pot of gold][solutionAction: got robbed]",
"[needGoodReason:got a magic protection][solutionAction: used it wrong and god is mad and curses the family]",
"[needGoodReason:have got a priceless gift][solutionAction: trade it with someone else for food]"
],
"story": [
"Long times ago there is \n#hero# lives near by the great wall. \n#badEvent# neighbors and relatives hear the news and come over to comfort him. However, He is not anxious about it. He laughs and says: \"How does anyone know if this is a not good thing?\" \n#goodEvent# \n One day, The end."
],
"badEvent": [
"One day #hero# got #needBadReason#"
],
"goodEvent":[
"After a few months pass, #solutionAction#"
],
"lacking": [
"Because of #needReason#, #loveInterest# needs #questObject.a# from distant #destination#.",
"'I am stricken with #needReason#,' says #loveInterest#. 'I need #questObject.a# to lift this burden.'"
]
}