@Kim_Kohler wrote:
Hi,
I have been trying to find my answer online but I can't find it. I bet the answer is supersimple, but I am pretty new to coding. =(
I am trying to make a endless looping ripple using a recursive class. The first ripple(expanding circle) works fine, but the second one gets stuck where it is initialized. I found that in the sub Object r2 does not update, but I cannot figure out how to solve this. Any ideas?
This is my ofApp.cpp:
void ofApp::draw(){ ofTranslate(ofGetWidth()/2, ofGetHeight()/2); test.hej(0, 0, 0.1); // staring r2 at 0.1 }
And this is my recursive class Test.cpp:
Test::Test(){ r1 = 2; counter = 0.1; // setting counter back to 0.1 so new sub Object start in the middle }; void Test::hej(float x, float y, float r2){ float n = 56.5; r2 = counter +1; // increasing r2 by 1 ofBeginShape(); for (float i = 0; i<360; i+=360/n){ x = 0+cos(i/n)*r2; y = 0+sin(i/n)*r2; // r2 is the reason the circles expands outwards, as it is increasing ofFill(); ofDrawCircle(x, y, r1); ofNoFill(); ofVertex(x, y); } ofEndShape(); float dist = ofDist(x, y, 0, 0); if (dist > 200){ Test subTest; subTest.hej(0, 0, 0.1); // starting sub Object at the same place as the first, in the middle, setting r2 to 0.1 } counter = r2; // counter saves this size of r2 for next loop, as it is initialized back to 0.1 in ofApp.cpp cout << r2 << endl; }
Thankful for any input!
Posts: 1
Participants: 1