@mitchallen/lsystem

0.25.8 • Public • Published

@mitchallen/lsystem

L-System Generator

Build Downloads Version

Buy Me a Coffee at ko-fi.com


Installation

$ npm init
$ npm install @mitchallen/lsystem --save


Usage

const factory = require('@mitchallen/lsystem');
const penTurtleFactory = require('@mitchallen/pen-turtle');
const svgFactory = require("@mitchallen/pen-svg")

function kochIsland() {
    let width = 1024,
        height = 1024;
    let writer = svgFactory.create({});
    let lsys = factory.create();
    // setup turtle
    let turtle = penTurtleFactory.create({
        color: 0x000000,
        width: 1,
    });
    // setup lsystem
    // add pen turtle to lsystem
    lsys.turtle = turtle;
    // define lsystem
    lsys.distance = 4;
    lsys.depth = 4;
    lsys.angle = 60;
    lsys.addRule("F", "F-F++F-F");
    lsys.axiom = "F++F++F";
    lsys.run();
    // write to svg
    writer
        .addPen(lsys.turtle,
            {
                color: 0x000000,
                fill: 0xFF0000,
                width: 1,
                transform: {
                    scale: { x: 2.0, y: 2.0 },
                    translate: { x: 140, y: 400 },
                }
            });
    let filename = 'koch-island.svg'
    let svg = writer.writeSVG({
        width,
        height,
        filename,
    });

    // print the SVG markup to the screen

    console.log(svg)

    console.log(`\n\nOpen ${filename} in your drawing program or browser.\n\n`)

}

kochIsland()

Documentation

Buy me a coffee!

If you like this package and find it useful, please show your appreciation and buy me a coffee!

Buy Me a Coffee at ko-fi.com

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.25.80latest

Version History

VersionDownloads (Last 7 Days)Published
0.25.80
0.25.70
0.25.60
0.25.50
0.25.40
0.25.30
0.25.20
0.25.00
0.24.00
0.23.00
0.22.00
0.21.00
0.20.00
0.19.00
0.18.30
0.18.20
0.18.10
0.18.00
0.17.00
0.16.00
0.15.00
0.14.00
0.13.00
0.12.00
0.11.00
0.10.10
0.10.00
0.9.00
0.8.00
0.7.00

Package Sidebar

Install

npm i @mitchallen/lsystem

Weekly Downloads

0

Version

0.25.8

License

MIT

Unpacked Size

10.3 kB

Total Files

4

Last publish

Collaborators

  • mitchallen