Created
November 1, 2018 04:11
-
-
Save zamfi/9edabb14dbc29bd0dbbedac5e13bfffa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> | |
| <script type="text/javascript" src="tracery.js"></script> | |
| <title>Text Generator</title> | |
| </head> | |
| <body> | |
| <button onclick="addNewTrace()">One more!</button> | |
| <div id="main"></div> | |
| <script type="text/javascript"> | |
| let rules = { | |
| start: ["In the year 2025, #protagonist# must #action# #antagonist#."], | |
| protagonist: ["#qty# #adj# #plnoun#", "one #adj# #noun#", "#protagonist# and #protagonist#"], | |
| adj: ["beleaguered", "sad", "lonely", "angry", "tiny", "giant", "#adj# #adj#", "very #adj#"], | |
| qty: ["three", "two", "twelve", "an army of"], | |
| noun: ["man", "dolphin", "zookeeper", "scientist", "robot"], | |
| plnoun: ["men", "dolphins", "zookeepers", "scientists", "robots"], | |
| action: ["save #target# from", "eat", "destroy", "look deep within to understand", "risk #protagonist# to save"], | |
| target: ["humanity", "the world", "one special lady", "snow white and the seven dwarves"], | |
| antagonist: ["#protagonist#"] | |
| } | |
| let grammar = tracery.createGrammar(rules); | |
| function addNewTrace() { | |
| var trace = grammar.flatten('#start#'); | |
| $('#main').append($('<div>').text(trace)); | |
| } | |
| addNewTrace(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment