GithubHelp home page GithubHelp logo

codeaudit / tracery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from galaxykate/tracery

0.0 3.0 0.0 7.46 MB

Tracery: a story-grammar generation library for javascript

License: Apache License 2.0

CSS 0.51% HTML 1.24% JavaScript 98.25%

tracery's Introduction

Welcome to Tracery!

A text-expansion library

There are many new examples of Tracery in use I also have an exciting new interactive tutorial

I strongly recommend using the minified library

Write grammar objects, get generative stories

An example grammar

{
	"name": ["Arjun","Yuuma","Darcy","Mia","Chiaki","Izzi","Azra","Lina"],
	"animal": ["unicorn","raven","sparrow","scorpion","coyote","eagle","owl","lizard","zebra","duck","kitten"],
	"mood": ["vexed","indignant","impassioned","wistful","astute","courteous"],
	"story": ["#hero# traveled with her pet #heroPet#.  #hero# was never #mood#, for the #heroPet# was always too #mood#."],
	"origin": ["#[hero:#name#][heroPet:#animal#]story#"]
}

Output of that grammar.

Of course, many grammars are more complex!

Lina traveled with her pet duck. Lina was never indignant, for the duck was always too indignant.
Yuuma traveled with her pet unicorn. Yuuma was never wistful, for the unicorn was always too indignant.
Azra traveled with her pet coyote. Azra was never wistful, for the coyote was always too impassioned.
Yuuma traveled with her pet owl. Yuuma was never wistful, for the owl was always too courteous.
Azra traveled with her pet zebra. Azra was never impassioned, for the zebra was always too astute.

How to use Tracery as a broswer library

Import tracery <script defer src="js/libs/tracery.js"></script>

Use the tracery object to create a Grammar object from a source object (specification below) tracery.createGrammar(spellbook);

The grammar can create Trace objects. A Trace is one possible expansion of a grammar. var trace = app.grammar.createTrace();

The trace can be expanded into a tree structure, step by step, or all at once. trace.expand(); Once expanded, the trace can create a 'flattened' version of itself: a single string of text. var myString = trace.flatten();

Or the grammar can generate a trace and flatten it, all in one step var myTitle = app.grammar.createFlattened()

Traces will start their expansions with the 'origin' symbol by default, but you can also create one from a rule (see "Rule Syntax" below), or from a symbol var trace = app.grammar.createTrace("A story about #character#"); var trace = app.grammar.createTraceFromSymbol("bookTitle");

Many traces can be working on a single grammar at the same time, without getting in each others way.

How to use Tracery as a Node.js library

Use this Node library created by George Buckenham: https://github.com/v21/tracery

Input

Syntax overview

Grammar

A grammar is a key-value storage system for rules.

Rule syntax

Each symbol should be followed by an array of text strings representing rules

  "emotion" : ["happy", "sad", "proud"],

or, if you're writing a long string of single words, you can use 'split'

  "emotion" : "happy sad reflective morose proud".split(" "),

Rules can also contain expansion symbols, words surrounded by #'s:

mainCharacter: ["Brittany the Wombat"],
story : ["This is a story about #mainCharacter#"]

Expansion symbols can have modifiers. Modifiers can change something about the string expansion of that symbol. #animal.capitalize# or #animal.a# or #animal.s#

name: ["Brittany"],
animal: ["wombat"],
story : ["This is a story about #name# the #animal.capitalize#"]

tracery's People

Contributors

dariusk avatar erbridge avatar galaxykate avatar johnicholas avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.