Recursive ripple gets stuck

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. =(

Apologize for posting openFrameworks code in the c ++ forum. But I really need some help and its basically the same thing. =)

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:

1
2
3
4
  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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 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!
Topic archived. No new replies allowed.