Is there a way to simplify this?

I am trying to make trailing rectangles, this is what I have right now and it works all though I was wondering is there a simpler way to do this? If say I wanted to do this for 10 rectangles.

void ofApp::setup(){
    x = 50;
    y = 50;
    x2 = 50;
    x3 = 50;

    xoff = 0.01;
    targetx = ofGetWidth()-100;

}

void ofApp::draw(){
    ofSetColor(150);
    x = ofLerp(x, targetx, 0.009);
    ofDrawRectangle(x, y, 100, 100);
    
    ofSetColor(200);
    
    x2 = ofLerp(x2, x, 0.05);
    ofDrawRectangle(x2, y, 100, 100);
    
    ofSetColor(255);
    
    x3 = ofLerp(x3, x2, 0.05);
    ofDrawRectangle(x3, y, 100, 100);
    
    }
}

you can use a vector like

vector <ofRectangle> 

move the first
and interpolate the position of the others in a loop

Hey just to add a bit to what dimitre posted, you can store lots of things of the same type in a std::vector or other container. An ofRectangle type would work, as would a glm::vec2 or glm::vec3 type, or even a custom type (like instances of your own struct or class). When they’re contained in a std::vector, you can iterate over all of them in a loop, call ofLerp(), ofDrawRectangle(), and other functions on each one as needed. The ofBook chapter on std::vector is awesome and quite helpful if you are not familiar with them.