Giter Club home page Giter Club logo

lsystems's Introduction

LSystems

NPM version

A little library for creating L-Systems, recently converted to typescript and webpack. React frontend here (github).

To compile, just npm install followed by npm run build. This should create lsystems.js which exports 3 classes under the package lsystems:

  • LSystem
  • LSystemRenderer
  • LSystemGenerator

There are also a couple basic tests for LSystem in src/tests

You should be able to see output in index.html, and an example of how the library may be used.

Note: you WILL need typescript globally installed

What is an LSystem?

Check out this pdf: http://algorithmicbotany.org/papers/abop/abop-ch1.pdf

What's inside?

Lsystem class provides:

  Lsystem(seed, rules);   //constructor
  step();                 //iterate once
  stepn(4);               //iterate 4 times

Renderer class:

  Renderer(config);         //constructor
  draw();                   //draw to the canvas

Generator class:

  singleRuleRandom(x);    //return a rule of length x

  ruleSetRandom();        //return a random ruleset

  randomSystem();         //return a random LSystem

  dragonCurve();          //return an LSystem that will render to the famous "dragon curve"

Properties on the renderer that can be passed in the config block (along with their default values):

(you must include a system and a canvas)

    divisor = 2;

    forwardStrings = ['F', 'E'];
    turnLeftStrings = ['-'];
    turnRightStrings = ['+'];

    RBGStrings = ['R', 'B', 'G']; //for changing colors
    lineColors = ['red', 'blue', 'green'];

    lineColor = "red";

    initialOrientation = 0;	//pointing up
    theta = Math.PI/this.divisor;
    increment = 12;

A minimal example

You can find this in index.html

      	var canvas1 = document.getElementById("canvas");

      	var data, system, renderer, canvas1, ii, kk;
        console.log(lsystems);

        system = (new lsystems.LSystemGenerator).dragonCurve();
        system.stepn(8);
        renderCfg = {
          system : system,
          canvas : canvas
        }
        renderer = new lsystems.LSystemRenderer(renderCfg);
        renderer.draw();

lsystems's People

Contributors

sleepdeprivation avatar weeperscreepers avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.