0.25.8 • Published 1 year ago
@mitchallen/lsystem v0.25.8
@mitchallen/lsystem
L-System Generator
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!
0.25.8
1 year ago
0.25.7
1 year ago
0.25.6
1 year ago
0.25.5
1 year ago
0.25.4
1 year ago
0.25.3
1 year ago
0.25.2
1 year ago
0.25.0
1 year ago
0.24.0
1 year ago
0.23.0
1 year ago
0.22.0
1 year ago
0.21.0
1 year ago
0.20.0
1 year ago
0.19.0
1 year ago
0.18.3
1 year ago
0.18.2
1 year ago
0.18.1
1 year ago
0.18.0
1 year ago
0.17.0
1 year ago
0.16.0
1 year ago
0.15.0
1 year ago
0.14.0
1 year ago
0.13.0
1 year ago
0.12.0
1 year ago
0.11.0
1 year ago
0.10.1
1 year ago
0.10.0
1 year ago
0.9.0
1 year ago
0.8.0
1 year ago
0.7.0
1 year ago