Get support for soyuka/lsystem

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

soyuka/lsystem

lsystem

A simple utility to produce L-System stacks. (16 sloc)

See: https://en.wikipedia.org/wiki/L-system

Usage:

var lsystem = require('lsystem')
/**
 * @param (v: String): String rule (see below)
 * @param {Number} iterations
 * @param {Mixed} initial value
 * @param (v: String): void callback with the next value
 */
lsystem(rule, 10, 'F', onnext)

/**
 * Koch curve formula:
 * variables : F
 * constants : +-
 * start  : F
 * rules  : (F → F+F−F−F+F)
 *
 * @param {String} v the letter to convert
 *
 * @return {String} the transformed string or the given one (constants)
 */
function rule (v) {
  switch (v) {
    case 'F':
      return 'F+F-F-F+F'
  }

  return v
}

const tree = []
function onnext(v) {
  tree.push(v)
}

console.log(tree)

API:

lsystem([number of occurences], [rule], [initial data])

Output of node example.js:

Algae
A
AB
ABA
ABAAB
FractalTree
0
1[0]0
11[1[0]0]1[0]0
1111[11[1[0]0]1[0]0]11[1[0]0]1[0]0
Cantor
A
ABA
ABABBBABA
ABABBBABABBBBBBBBBABABBBABA
Koch
F
F+F-F-F+F
F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F
F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F+F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F+F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F
Fractal
X
F[-X][X]F[-X]+FX
FF[-F[-X][X]F[-X]+FX][F[-X][X]F[-X]+FX]FF[-F[-X][X]F[-X]+FX]+FFF[-X][X]F[-X]+FX
FFFF[-FF[-F[-X][X]F[-X]+FX][F[-X][X]F[-X]+FX]FF[-F[-X][X]F[-X]+FX]+FFF[-X][X]F[-X]+FX][FF[-F[-X][X]F[-X]+FX][F[-X][X]F[-X]+FX]FF[-F[-X][X]F[-X]+FX]+FFF[-X][X]F[-X]+FX]FFFF[-FF[-F[-X][X]F[-X]+FX][F[-X][X]F[-X]+FX]FF[-F[-X][X]F[-X]+FX]+FFF[-X][X]F[-X]+FX]+FFFFFF[-F[-X][X]F[-X]+FX][F[-X][X]F[-X]+FX]FF[-F[-X][X]F[-X]+FX]+FFF[-X][X]F[-X]+FX
Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2