Example #1
0
// sets j, k, n, o, p, r, s to the next permutation
// returns true until the permutations run out then returns false
bool next_permutation(void)
{
    for (int x = 6; x >= 0; x--) {
        indices[x]++;

        if (indices[x] == 19) {
            if (!x) {
                return false;
            }
            moveback(x, 18);
            indices[x] = x;
            continue;
        }

        swap(x, indices[x]);
        break;
    }

    j = elem[0];
    k = elem[1];
    n = elem[2];
    o = elem[3];
    p = elem[4];
    r = elem[5];
    s = elem[6];

    return true;
}
Example #2
0
int SundayMatcher(char *T, char *P)
{
	int TLen, PLen, pos;
	if (NULL == P)
		return 0;
	if (NULL == T)
		return -1;

	TLen = strlen(T);
	PLen = strlen(P);

	if (0 == PLen)
		return 0;
	
	pos = 0;
	while (pos <=TLen-PLen)
	{
		if (strncmp(T + pos, P, PLen))
		{
			if (pos == TLen - PLen)
				return -1;
			pos += moveback(P, PLen, T[pos + PLen]);
		}
		else
			return pos;
	}
	return -1;
}
//--------------------------------------------------------------
void ofApp::update(){
    ofSetWindowTitle(ofToString(ofGetFrameRate()) + " fps");

    if ( keyAnimate ) {
        for (int i = 0 ; i < maxfltPtlNum; ++i) {
            fltPtlPos[i] = fltPtlPos[i] + fltPtlSpeed[i];
            if (fltPtlPos[i].distance(winCen) < enterThread) {
                //startsearch Index to cut the unnecessary compare;
                cutNumEst = 0.23 * 4 * pow(enterThread/(maxfltRadius + minfltRadius), 2); //the estimated number to cut;
                
                if (aggPtlPos.size() > (int)cutNumEst) {
                    cutIndex = int(0.55 * cutNumEst);
                    for (int j = cutIndex; j < aggPtlPos.size() ; ++j) {
                        
                        float distCompare =aggPtlRadius[j] + fltPtlRadius[i];
                        
                        if (fltPtlPos[i].distance(aggPtlPos[j]) < distCompare) {
                            indexHit = i;
                            //move floating particle back to avoid overlapping/ control overlaping gap
                            fltPtlPos[i] = moveback(fltPtlPos[i], aggPtlPos[j], aggPtlRadius[j], fltPtlRadius[i]);
                            
                            ofFloatColor tempMeshCol;
                            
                            tempMeshCol.setHsb(ofMap(j, 0, maxAggPtlNum, 0.0f, 1.f) , 0.8, 0.95);
                            
                            dlaMesh.addVertex(aggPtlPos[j]);
                            dlaMesh.addColor(tempMeshCol);
                            dlaMesh.addVertex(fltPtlPos[i]);
                            dlaMesh.addColor(tempMeshCol);
                            
                            float fixedDis = fltPtlPos[i].distance(winCen);
                            if (fixedDis > enterThread) {
                                enterThread = 2.2 * maxfltRadius + fixedDis;
                            }
                            
                            aggPtlPos.push_back( fltPtlPos[i] );
                            aggPtlRadius.push_back( fltPtlRadius[i] );
                            
                            //regenerate pos and radius
                            fltPtlresetbyIndex(i);
                            
                            if (aggPtlPos.size() > maxAggPtlNum) {
                                keyAnimate = false;
                            }
                        }else if (fltPtlPos[i].distance(winCen) > maxGenRadius){
                            fltPtlresetbyIndex(i);
                        }
                        
                    }
                }else{
                    for (int j = 0; j < aggPtlPos.size() ; ++j) {
                        
                        float distCompare =aggPtlRadius[j] + fltPtlRadius[i];
                        
                        if (fltPtlPos[i].distance(aggPtlPos[j]) < distCompare) {
                            indexHit = i;
                            //move floating particle back to avoid overlapping/ control overlaping gap
                            fltPtlPos[i] = moveback(fltPtlPos[i], aggPtlPos[j], aggPtlRadius[j], fltPtlRadius[i]);
                            
                            ofFloatColor tempMeshCol;
                            
                            tempMeshCol.setHsb(ofMap(j, 0, maxAggPtlNum, 0.0f, 1.f) , 0.8, 0.95);
                            
                            dlaMesh.addVertex(aggPtlPos[j]);
                            dlaMesh.addColor(tempMeshCol);
                            dlaMesh.addVertex(fltPtlPos[i]);
                            dlaMesh.addColor(tempMeshCol);
                            
                            float fixedDis = fltPtlPos[i].distance(winCen);
                            if (fixedDis > enterThread) {
                                enterThread = 2.2 * maxfltRadius + fixedDis;
                            }
                            
                            aggPtlPos.push_back( fltPtlPos[i] );
                            aggPtlRadius.push_back( fltPtlRadius[i] );
                            
                            //regenerate pos and radius
                            fltPtlresetbyIndex(i);
                            
                            if (aggPtlPos.size() > maxAggPtlNum) {
                                keyAnimate = false;
                            }
                        }else if (fltPtlPos[i].distance(winCen) > maxGenRadius){
                            fltPtlresetbyIndex(i);
                        }
                        
                    }
                }
                
            }
            
        }
    }
    
    if (autoZoom) {
        camDist = ofMap(aggPtlPos.size(), 500, 1000+1.5*aggPtlPos.size(), 500, 2000);
        topCam.setDistance(camDist);
    }

}