Space Colonization algorithm implementation in openFrameworks
C++ Makefile
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
example-3d add padding Sep 5, 2017
example-ofxenvelope fix windows error Sep 5, 2017
img add cover Jul 2, 2017
src add padding option Aug 4, 2017
.appveyor.yml fix appveyor Jul 1, 2017
.gitignore add to gitignore Jun 30, 2017
.travis.yml add dependencies to travis Jun 30, 2017 Update Apr 19, 2018
ofxaddons_thumbnail.png add thumb Aug 2, 2017


Build status Build status


This addon is an openFrameworks implementation of the paper Modeling Trees with a Space Colonization Algorithm by Adam Runions, Brendan Lane, and Przemyslaw Prusinkiewicz.


It requires ofxBranchesPrimitive. The example example-ofxenvelope requires the addon ofxEnvelope


//in your header file
ofxSpaceColonization tree;

// in your App.cpp file
void ofApp::setup(){;

void ofApp::update(){

void ofApp::draw(){

This will generate a tree using this standard options:

static const ofxSpaceColonizationOptions defaultSpaceColOptions = {
    150,                             // maxDist, leaves are attractive if closer than this distance
    10,                              // minDist, leaves are attractive if farther than this distance
    150,                             // trunkLength, the length of the trunk
    glm::vec4(0.0f,0.0f,0.0f, 1.0f), // rootPosition, the position of the root
    glm::vec3(0.0f, 1.0f, 0.0f),     // rootDirection, the direction on which the tree will starts to grow
    7,                               // branchLength, the length of each branch
    false,                           // doneDrowing, a value that indicates when the grow process is done
    false,                           // cap, if the cylinders that compose the branches have caps or not
    2.0,                             // radius, the radius of the branch
    16,                              // resolution, the resolution of the cylinders that compose the geometry
    1,                               // textureRepeat, how many times a texture has to be repeated on a branch
    0.9997                           // radiusScale, how much the radius will increase or decrease at each interaction

You can specify yours options and pass it to the tree using the setup method:

void ofApp::setup(){
    auto myOpt = ofxSpaceColonizationOptions({
       // ...

The form of the tree changes depending on these options and on the position of the leaves. By default, some default leaves are provided but you can provide your leaves by using the setLeavesPositions() method. It takes a vector<glm::vec3> as argument.

void ofApp::setup(){
    vector<glm::vec3> points;
    // ... fullfill the vector

I've created an addon that can be used to generate the points, it is called ofxEnvelope and you can see in the example example-ofxenvelope how to use it.


The grow method takes a glm::vec3 as optional parameter. This vector can be used to move the leaves, like this Example:

void ofApp::update(){
  float t = ofGetElapsedTimef();
  float n = ofSignedNoise(t * windFreq) * windAmpl;
  auto wind = glm::vec3(n,0.0,0.0); // a weird wind that only breezes on the x axis


example-3d example-3d

example-ofxenvelope example-ofxenvelope




Procedurally Generated Trees with Space Colonization Algorithm in XNA C#

Daniel Shiffman Video