Use Lindenmayer systems as SVG patterns. Work in progess. In particular, the following is missing:
- tests
- helpful example code that yields a nice-looking pattern
- publishing to npm
- compatibility with
svg-patterns
npm install svg-patterns-lindenmayer
const generate = require('svg-patterns-lindenmayer')
const svg = generate(5, 'A', {
A: 'B',
B: 'F++OB'
})
console.log(svg)
generate(iterations, axiom, rules, [opt])
iterations
should be an integer >0
. It determines how often rule identifiers in axiom
will be evaluated.
axiom
must be a string of multiple rule identifiers (e.g. 'AA[B+]'
) or an array of individual identifiers (e.g. ['A'. 'A', '[', 'B', '+', ']']
).
rules
must be an object. Each key is a rule identifier, each value must be a string of rule identifiers (e.g. AB
) or an array of rule identifiers (e.g. ['A', 'B']
), which will be used during evaluation.
opt
is optional and must be an object. It may have the following keys:
colors
: An array of colors to be used.distance
: The distance to move forward. Used by e.g.F
,M
.atoms
: An object of atoms. Each key is the identifier of the atom. Each value must be a function which executes a rendering operation. See the source code for details.
If you have a question or have difficulties using svg-patterns-lindenmayer
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.