0.0.2 • Published 7 years ago
graphgram v0.0.2
graphgram
A graph grammar library. Transforms graphlib graphs using a configurable, JSON-described graph grammar (see e.g. these slides by Matilde Marcolli, or this RPS article about Joris Dormans' Unexplored (which uses the technique to generate "cyclic" levels), or this Wikipedia page).
Can be used for game levels, procedural content, simulations, etc.
Scripts
- bin/transform.js: transform a graph using a graph grammar
- bin/lattice.js: create an N*N square lattice
- bin/graph2dot.js: the
transform.js
graphlib-to-Graphviz feature, as a separate script
Example grammars
- grammars/dungeon.js: choose-your-own dungeon
- grammars/level.js: a roguelike level (should be initialized with a square lattice)
- grammars/test.js: a test grammar
API usage
var graphlib = require('graphlib'),
Grammar = require('../graphgram').Grammar,
fs = require('fs')
var grammarFile = 'grammars/dungeon.json'
var grammarJson = JSON.parse (fs.readFileSync (grammarFile).toString())
var grammar = new Grammar (grammarJson)
var graph = grammar.evolve().graph
The resulting graph
is a graphlib object.