Hey everyone,
I am working on a project where I am attempting to draw a root / tree like structures and I have figured out the recursive part of it but I am struggling to work out how I can progressively draw one line at a time.
I would like to start from one root / branch and once that is fully drawn, start drawing the next two that are branching out of it and so on. I went through the forum and found some threads I thought would help but nothing specifically regarding this issue so any help would be much appreciated
Here is my code to make it easier for you to understand:
//--------------------------------------------------------------//--------------------------------------------------------------//
void RootsSource::setup(){
ofBackground(255);
ofSetLineWidth(1);
ofSetFrameRate(30);
// t = ofGetElapsedTimeMillis();
angle = 35;
len = 200;
lenRatio = 0.67;
}
//--------------------------------------------------------------
void RootsSource::update(){
locY++;
}
//--------------------------------------------------------------
void RootsSource::draw(){
ofSetColor(0);
ofTranslate(ofGetWidth()/2, 150);
root(len, angle);
}
//--------------------------------------------------------------
void RootsSource::root(int len, int angle){
if (locY <= len) {
ofDrawLine(0, 0, 0, locY);
}
else if (locY > len) {
ofDrawLine(0, 0, 0, len);
}
ofTranslate(0, len);
if (len > 5) {
ofPushMatrix();
ofRotateDeg(angle);
root(len*lenRatio, angle);
ofPopMatrix();
ofPushMatrix();
ofRotateDeg(-angle);
root(len*lenRatio, angle);
ofPopMatrix();
}
}