← Back

ofxLSystem

github.com/edap/ofxLSystem · @edap
OF 0.10 Algorithms

3D turtle graphics interpretation of L-Systems

39 10 Last commit 7y ago Created 10y ago

Forks

Forks pushed to more recently than edap/ofxLSystem itself, plus any admin-confirmed fork with commits of its own — worth checking if you're hitting issues with the original.

ofxyz/ofxLSystem by @ofxyz · ★ 0 · pushed 2mo ago

README

ofxLSystem



Build status Build status

This addon has a dependency on ofxLSystemGrammar. Download it and add it to your addon folder

ofxLSystem is a 3D graphic turtle graphic interpretation of L-Syestems. In the readme of ofxLSystemGrammar you can find some information about L-System. This addon can be used to generate meshes as the following ones:

example example example example example

Supported platforms



It is currently tested on mac, linux and windows and the current version of openFrameworks in master

On linux, you need g++ > 4.9 and the -std=gnu++14 flag. Otherwise you will have an error about std::regex_iterator. This flag is the default since OF 0.9.3, just in case you set it to std=c++11 as described in this [post]( https://forum.openframeworks.cc/t/openframeworks-0-9-qtcreator/21312/7).

Usage



In your header file include ofxLSystem and declare an instance of it. Declare also a material, it will be applied to the tree's mesh.

#include "ofxLSystem.h"
// ...
ofxLSystem tree
ofMaterial treeMaterial


In your ofApp.cpp

void ofApp::setup(){
  treeMaterial.setDiffuseColor(ofFloatColor::blueSteel)
  tree.setStep(4);
  tree.build();
}


void ofApp::draw(){
  treeMaterial.begin();
  tree.draw();
  treeMaterial.end();
}


tree.setAxiom("F") tells to ofxLSystem to use F as axiom, tree.setRules({"F -> FF+F"}) to use F -> FF+F as reproduction rule and tree.setStep(4) to iterate 4 times. Have a look into ofxLSystemGrammar or in the 2 examples in this project for more L-System examples.

By default, each L-System is initialized with this parameters:

typedef map<string,float> Constants;

vector<string>    rulesContainer = {"F -> F+F"};
string            axiom = "F";
bool              randomYRotation = false;
int               depth = 1;
float             theta = 25.00;
float             stepWidth = 10.00;
bool              scaleWidth = false;
float             stepLength = 100.00;
map<string,float> constants = Constants();


you can overwrite the default parameters using these methods:

void setAxiom(string _axiom);
void setRules(vector<string> _rulesContainer);
void setTheta(float _theta);
void setRandomZRotation(bool _randomYRotation);
void setStep(int _depth);
void setScaleWidth(bool _scaleWidht);
void setStepWidth(float _stepWidth);
void setStepLength(float _stepLength);
void setConstants(map<string,float> _Constants);


For example, the following snippet:

ofxLSystem tree;
map<string, float> constants;
constants.insert(make_pair("R", 1.456));

tree.setAxiom("A(100)");
tree.setRules({"A(s) -> F(s)+A(s/R)"});
tree.setRandomYRotation(true);
tree.setConstants(constants);
tree.setStep(4);
tree.setScaleWidth(true);
tree.setStepLength(90);


Generates a tree like this:

example

Examples



Get this addon

HTTPS
SSH