A function that runs "once" in 8 seconds

Hello, I want to make a function where the location and color of the square change every 8 seconds.

This function must be executed once every eight seconds. However, it will continue to run for 8 seconds, so I want to solve this problem.

How should I use the time?

	if ((int)ofGetElapsedTimef() != 0 && (int)ofGetElapsedTimef() % 8 == 0) {

		for (int i = 0; i < 17800; i++)
		{
			randomA[i] = 0;
		}

		index += 1;
		zpos = -300;
		a = 255;
	}

float nextCall = 0;
void draw() {
    if (nextCall < ofGetElapsedTimef()) {
        nextCall = ofGetElapsedTimef() + 8;
        intermittentFunction();
    }
}