@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

Readme

Keywords

Package Sidebar

Install

npm i @mitchallen/lsystem

Weekly Downloads

4

Version

0.25.8

License

MIT

Unpacked Size

10.3 kB

Total Files

4

Last publish

Collaborators

  • mitchallen