Properly animating tree traversal

Hi everyone,

Working on traversing a tree structure that I’ve built (Essentially, the nodes are a linked list with multiple children), I am wanting to simulate a kind of capillary movement. Currently the update function works, it properly walks through the structure and updates it’s location, but this can’t solve my problem with walking through and updating colors slowly, over time. Does anyone have any advice on how I might want to take this on? I’ve tried messing with threads, in a perfect world all I would really be doing is slowing down each recursive call to updateMesh.

The entire project with an example can be found here:

//--------------------------------------------------------------
void ofxGrowth::update(){
    b_step = false;
    
    current_mesh_id = 0;
    
    root->update();
    
    ofSetLineWidth(stroke_width);
    
    updateMesh(root, meshes[0].get(),0);
}

//--------------------------------------------------------------
void ofxGrowth::updateMesh(ofxGrowthNode * current_node, ofMesh * current_mesh, int mesh_node_id){
    current_mesh->setVertex(mesh_node_id, current_node->location);
    current_mesh->setColor(mesh_node_id, colorLevels(current_node->level));
    
    for(int i = 0; i < current_node->children.size(); i++){
        if(i > 0){
            current_mesh = meshes[current_mesh_id + 1].get();
            current_mesh_id = current_mesh_id + 1;
            mesh_node_id = 0;
            
            current_mesh->setVertex(mesh_node_id, current_node->location);
            current_mesh->setColor(mesh_node_id, colorLevels(current_node->level));
            
            mesh_node_id = 1;
            
            current_node = current_node->children[i].get();
            
            updateMesh(current_node, current_mesh, mesh_node_id);
        }else{
            mesh_node_id++;
            
            current_node = current_node->children[i].get();
            
            updateMesh(current_node, current_mesh, mesh_node_id);
        }
    }
}
1 Like