//-------------------------------------------------------------- void ofApp::update() { if (startDraw<20) { startDraw ++ ; } ofEnableAlphaBlending(); rgbaFbo.begin(); drawFboTest(); for (int i=0; i<NUM; i++) { pens[i].update(); } rgbaFbo.end(); x += speedX; y += speedY; if (x >= 0 || x <= -167.5) { speedX = speedX*-1; } if (y >= 0 || y <= -390) { speedY = speedY*-1; } }
//-------------------------------------------------------------- void testApp::update(){ //fbo rgbaFboFloat.begin(); drawFboTest(); rgbaFboFloat.end(); // sort all the dwgParti: sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) > 50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } bgParti[i]->addRepulsionForce(mouseX, mouseY, 40, 0.4); } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } // wrap torroidally. for (int i = 0; i < bgParti.size(); i++){ ofVec2f pos = bgParti[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; bgParti[i]->pos = pos; } //osc // hide old messages for(int i = 0; i < NUM_MSG_STRINGS; i++){ if(timers[i] < ofGetElapsedTimef()){ msg_strings[i] = ""; } } // check for waiting messages while(receiver.hasWaitingMessages()){ // get the next message ofxOscMessage m; receiver.getNextMessage(&m); for (int i = 0; i < dwgParti.size(); i++){ // check for mouse moved message if(m.getAddress() == "/accel/x"){ bgParti[i]->r3 = m.getArgAsFloat(0); bgParti[i]->vel.x += m.getArgAsFloat(0); cout << m.getArgAsFloat(0) << endl; } if(m.getAddress() == "/accel/y"){ bgParti[i]->r2 = m.getArgAsFloat(0); bgParti[i]->vel.y += m.getArgAsFloat(0); } if(m.getAddress() == "/accel/z"){ bgParti[i]->r1 = m.getArgAsFloat(0); bgParti[i]->vel.z += m.getArgAsFloat(0); } if(m.getAddress() == "/hue"){ bgParti[i]->c.setHue(m.getArgAsFloat(0)); } if(m.getAddress() == "/sat"){ bgParti[i]->c.setSaturation(m.getArgAsFloat(0)); } else{ // unrecognized message: display on the bottom of the screen string msg_string; msg_string = m.getAddress(); msg_string += ": "; for(int i = 0; i < m.getNumArgs(); i++){ // get he argument type msg_string += m.getArgTypeName(i); msg_string += ":"; // display the argument - make sure we get the right type if(m.getArgType(i) == OFXOSC_TYPE_INT32){ msg_string += ofToString(m.getArgAsInt32(i)); } else if(m.getArgType(i) == OFXOSC_TYPE_FLOAT){ msg_string += ofToString(m.getArgAsFloat(i)); } else if(m.getArgType(i) == OFXOSC_TYPE_STRING){ msg_string += m.getArgAsString(i); } else{ msg_string += "unknown"; } } // add to the list of strings to display msg_strings[current_msg_string] = msg_string; timers[current_msg_string] = ofGetElapsedTimef() + 5.0f; current_msg_string = (current_msg_string + 1) % NUM_MSG_STRINGS; // clear the next line msg_strings[current_msg_string] = ""; } } } ofPushView(); ofPushStyle(); ofPushMatrix(); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofClear(0, 255); float fade = abs(sin( ofGetElapsedTimef()*0.099 )); ofSetColor( ofMap( fade , 0.0f, 0.5f, 0.0f, 1.0f, true) * 255,255); ofDisableBlendMode(); ofPopMatrix(); ofPopView(); ofPopStyle(); ofSetWindowTitle(ofToString(ofGetFrameRate())); //osc // hide old messages for(int i = 0; i < NUM_MSG_STRINGS; i++){ if(timers[i] < ofGetElapsedTimef()){ msg_strings[i] = ""; } } // check for waiting messages while(receiver.hasWaitingMessages()){ // get the next message ofxOscMessage m; receiver.getNextMessage(&m); for (int i = 0; i < dwgParti.size(); i++){ // check for mouse moved message if(m.getAddress() == "/accel/x"){ dwgParti[i].r3 = m.getArgAsFloat(0); dwgParti[i].vel.x += m.getArgAsFloat(0); cout << m.getArgAsFloat(0) << endl; } if(m.getAddress() == "/accel/y"){ dwgParti[i].r2 = m.getArgAsFloat(0); dwgParti[i].vel.y += m.getArgAsFloat(0); } if(m.getAddress() == "/accel/z"){ dwgParti[i].r1 = m.getArgAsFloat(0); dwgParti[i].vel.z += m.getArgAsFloat(0); } if(m.getAddress() == "/hue"){ dwgParti[i].c.setHue(m.getArgAsFloat(0)); } if(m.getAddress() == "/sat"){ dwgParti[i].c.setSaturation(m.getArgAsFloat(0)); } else{ // unrecognized message: display on the bottom of the screen string msg_string; msg_string = m.getAddress(); msg_string += ": "; for(int i = 0; i < m.getNumArgs(); i++){ // get he argument type msg_string += m.getArgTypeName(i); msg_string += ":"; // display the argument - make sure we get the right type if(m.getArgType(i) == OFXOSC_TYPE_INT32){ msg_string += ofToString(m.getArgAsInt32(i)); } else if(m.getArgType(i) == OFXOSC_TYPE_FLOAT){ msg_string += ofToString(m.getArgAsFloat(i)); } else if(m.getArgType(i) == OFXOSC_TYPE_STRING){ msg_string += m.getArgAsString(i); } else{ msg_string += "unknown"; } } // add to the list of strings to display msg_strings[current_msg_string] = msg_string; timers[current_msg_string] = ofGetElapsedTimef() + 5.0f; current_msg_string = (current_msg_string + 1) % NUM_MSG_STRINGS; // clear the next line msg_strings[current_msg_string] = ""; } } } // number == 1 +++++++++++++++++++++++++++++++++++++ if(number==1) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 0.1; bgParti[i]->cohesion.distance = 50; bgParti[i]->alignment.strength = 0.7; bgParti[i]->alignment.distance = 42; bgParti[i]->seperation.strength = 0.7; bgParti[i]->seperation.distance = 38; bgParti[i]->damping = 0.08; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) > 50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } // for (int i = 0; i < bgParti.size(); i++){ // bgParti[i]->c.set(ofRandom(100,255),0,ofRandom(0,50),50); // } // // // for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } // wrap torroidally. for (int i = 0; i < bgParti.size(); i++){ ofVec2f pos = bgParti[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; bgParti[i]->pos = pos; } }; // number == 2 addAttractionForce to Mouse +++++++++++++++++++++++++++++++++++++ if(number==2) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 0.76; bgParti[i]->cohesion.distance = 50; bgParti[i]->alignment.strength = 0.5; bgParti[i]->alignment.distance = 130; bgParti[i]->seperation.strength = 0.4; bgParti[i]->seperation.distance = 157; bgParti[i]->damping = 0.192; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) > 50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } // wrap torroidally. for (int i = 0; i < bgParti.size(); i++){ ofVec2f pos = bgParti[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; bgParti[i]->pos = pos; } } // number == 3 addRepulsionForce to Mouse +++++++++++++++++++++++++++++++++++++ if(number==3) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 0.2; bgParti[i]->cohesion.distance = 200; bgParti[i]->alignment.strength = 0.24; bgParti[i]->alignment.distance = 198; bgParti[i]->seperation.strength = 0.4; bgParti[i]->seperation.distance = 33; bgParti[i]->damping = 0.029; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) > 50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } // wrap torroidally. for (int i = 0; i < bgParti.size(); i++){ ofVec2f pos = bgParti[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; bgParti[i]->pos = pos; } } // number == 4 seperation.distance +++++++++++++++++++++++++++++++++++++ if(number == 4) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 0.19; bgParti[i]->cohesion.distance = 200; bgParti[i]->alignment.strength = 0.2; bgParti[i]->alignment.distance = 175; bgParti[i]->seperation.strength = 0.46; bgParti[i]->seperation.distance = 200; bgParti[i]->damping = 0.45; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) > 50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } // wrap torroidally. for (int i = 0; i < bgParti.size(); i++){ ofVec2f pos = bgParti[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; bgParti[i]->pos = pos; } } // number == 5 +++++++++++++++++++++++++++++++++++++ if(number == 5) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 0.5; bgParti[i]->cohesion.distance = 100; bgParti[i]->alignment.strength = 0.38; bgParti[i]->alignment.distance = 52; bgParti[i]->seperation.strength = 0.9; bgParti[i]->seperation.distance = 15; bgParti[i]->damping = 0.68; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) > 50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } // wrap torroidally. for (int i = 0; i < bgParti.size(); i++){ ofVec2f pos = bgParti[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; bgParti[i]->pos = pos; } } // number == 6 repulsion = sound +++++++++++++++++++++++++++++++++++++ if(number == 6) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 0.20; bgParti[i]->cohesion.distance = 10; bgParti[i]->alignment.strength = 0.31; bgParti[i]->alignment.distance = 200; bgParti[i]->seperation.strength = 0.4; bgParti[i]->seperation.distance = 2; bgParti[i]->damping = 0.20; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } // wrap torroidally. for (int i = 0; i < bgParti.size(); i++){ ofVec2f pos = bgParti[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; bgParti[i]->pos = pos; } } // number == 7 repulsion +++++++++++++++++++++++++++++++++++++ if(number == 7) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 0.20; bgParti[i]->cohesion.distance = 100; bgParti[i]->alignment.strength = 0.31; bgParti[i]->alignment.distance = 20; bgParti[i]->seperation.strength = 0.4; bgParti[i]->seperation.distance = 2; bgParti[i]->damping = 0.8; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } // wrap torroidally. for (int i = 0; i < bgParti.size(); i++){ ofVec2f pos = bgParti[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; bgParti[i]->pos = pos; } } // number == 8 +++++++++++++++++++++++++++++++++++++ if(number == 8) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 0.43; bgParti[i]->cohesion.distance = 13.3; bgParti[i]->alignment.strength = 0.2; bgParti[i]->alignment.distance = 16.7; bgParti[i]->seperation.strength = 0.73; bgParti[i]->seperation.distance = 105; bgParti[i]->damping = 0.3; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } } // number == 9 +++++++++++++++++++++++++++++++++++++ if(number == 9) { // background dwgParti sort( bgParti.begin(), bgParti.end(), comparisonFunction ); for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->cohesion.strength = 1; bgParti[i]->cohesion.distance = 200; bgParti[i]->alignment.strength = 0.5; bgParti[i]->alignment.distance = 200; bgParti[i]->seperation.strength = 0.77; bgParti[i]->seperation.distance = 84.4; bgParti[i]->damping = 0.2; } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->resetForce(); } for (int i = 0; i < bgParti.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >50) break; if (i != j){ bgParti[i]->addForFlocking(*bgParti[j]); } } } for (int i = 0; i < bgParti.size(); i++){ bgParti[i]->addFlockingForce(); bgParti[i]->addDampingForce(); bgParti[i]->update(); } } // number == 11 == draw +++++++++++++++++++++++++++++++++++++ // font dwgParti if(number == 11) { for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].resetForce(); } blendMode = OF_BLENDMODE_SCREEN; for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addAttractionForce(mouseX, mouseY, 1000, 0.5); dwgParti[i].alignment.strength = scaledVol*2000; dwgParti[i].c.set(255,ofRandom(100,250),255); for (int j = 0; j < i; j++){ if (bRepel){ dwgParti[i].addRepulsionForce(dwgParti[j], radius, strength); } else { dwgParti[i].addAttractionForce(dwgParti[j], radius, strength); } } } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addDampingForce(); dwgParti[i].update(); } } // number == 12 == draw +++++++++++++++++++++++++++++++++++++ // font dwgParti if(number == 12) { // font dwgParti for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].resetForce(); } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addAttractionForce(mouseX, mouseY, 1000, 0.5); // dwgParti[i].scl.x = 500; // dwgParti[i].scl.y = 500; for (int j = 0; j < i; j++){ if (bRepel){ dwgParti[i].addRepulsionForce(dwgParti[j], radius + smoothedVol * 3000, strength); } else { dwgParti[i].addAttractionForce(dwgParti[j], radius , strength); } } } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addDampingForce(); dwgParti[i].damping = 0.1; dwgParti[i].update(); } } // number == 13 == draw +++++++++++++++++++++++++++++++++++++ // font dwgParti if(number == 13) { // font dwgParti for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].resetForce(); } for (int i = 0; i < dwgParti.size(); i++){ for (int j = 0; j < dwgParti.size(); j++){ if (i != j){ dwgParti[i].addForFlocking(dwgParti[j]); } } } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].damping = smoothedVol*200; } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addFlockingForce(); dwgParti[i].addDampingForce(); dwgParti[i].update(); } // wrap torroidally. for (int i = 0; i < dwgParti.size(); i++){ ofVec2f pos = dwgParti[i].pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; dwgParti[i].pos = pos; } } // number == 14 == draw +++++++++++++++++++++++++++++++++++++ // font dwgParti if(number == 14) { for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].resetForce(); } for (int i = 0; i < dwgParti.size(); i++){ for (int j = 0; j < dwgParti.size(); j++){ if (i != j){ dwgParti[i].addForFlocking(dwgParti[j]); } } // this was something we tried in class (partitcle move away from mouse...) dwgParti[i].addRepulsionForce(mouseX, mouseY, 40, 0.4); } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addFlockingForce(); dwgParti[i].addDampingForce(); dwgParti[i].update(); } // wrap torroidally. for (int i = 0; i < dwgParti.size(); i++){ ofVec2f pos = dwgParti[i].pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; dwgParti[i].pos = pos; } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].seperation.distance = smoothedVol*1000 ; dwgParti[i].seperation.strength = 23; dwgParti[i].damping = 0.13; dwgParti[i].addAttractionForce(mouseX, mouseY, 1000, 0.5); } } // number == 15 == Launch +++++++++++++++++++++++++++++++++++++ if(number == 15) { for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].resetForce(); } for (int i = 0; i < dwgParti.size(); i++){ for (int j = 0; j < dwgParti.size(); j++){ if (i != j){ dwgParti[i].addForFlocking(dwgParti[j]); } } // this was something we tried in class (partitcle move away from mouse...) dwgParti[i].addRepulsionForce(mouseX, mouseY, 40, 0.4); } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addFlockingForce(); dwgParti[i].cohesion.strength = smoothedVol*100; dwgParti[i].damping = 0.05; dwgParti[i].addDampingForce(); dwgParti[i].update(); } // wrap torroidally. for (int i = 0; i < dwgParti.size(); i++){ ofVec2f pos = dwgParti[i].pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; dwgParti[i].pos = pos; } } // number == 17 == Launch +++++++++++++++++++++++++++++++++++++ if(number == 17) { for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].resetForce(); } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addAttractionForce(mouseX, mouseY, 1000, 0.5); dwgParti[i].c.set(ofRandom(100,255), ofRandom(100,255), ofRandom(100,255)); for (int j = 0; j < i; j++){ if (bRepel){ dwgParti[i].addRepulsionForce(dwgParti[j], radius+200, strength); } else { dwgParti[i].addAttractionForce(dwgParti[j], radius, strength); } } } for (int i = 0; i < dwgParti.size(); i++){ dwgParti[i].addDampingForce(); dwgParti[i].update(); } } //tail testing timePoint temp; temp.t = ofGetElapsedTimef() - startTime; pts.push_back(temp); if(number==0) { if (pts.size() > 750){ pts.erase(pts.begin()); } } }
//-------------------------------------------------------------- void testApp::update(){ panel.update(); rgbaFboFloat.begin(); drawFboTest(); rgbaFboFloat.end(); // sort all the particles: sort( particles.begin(), particles.end(), comparisonFunction ); for (int i = 0; i < particles.size(); i++){ particles[i]->cohesion.distance = panel.getValueF("COHESION_RADIUS"); particles[i]->alignment.distance = panel.getValueF("ALIGNMENT_RADIUS"); particles[i]->seperation.distance = panel.getValueF("SEPERATION_RADIUS"); particles[i]->cohesion.strength = panel.getValueF("COHESION_STRENGTH"); particles[i]->alignment.strength = panel.getValueF("ALIGNMENT_STRENGTH"); particles[i]->seperation.strength = panel.getValueF("SEPERATION_STRENGTH"); particles[i]->damping = panel.getValueF("DAMPING"); } for (int i = 0; i < particles.size(); i++){ particles[i]->resetForce(); } // for (int i = 0; i < particles.size(); i++){ // for (int j = 0; j < particles.size(); j++){ // if (i != j){ // particles[i]->addForFlocking(*particles[j]); // } // } // particles[i]->addRepulsionForce(mouseX, mouseY, 40, 0.4); // } for (int i = 0; i < particles.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(particles[j]->pos.x - particles[i]->pos.x) > 50) break; if (i != j){ particles[i]->addForFlocking(*particles[j]); } } particles[i]->addRepulsionForce(mouseX, mouseY, 40, 0.4); } for (int i = 0; i < particles.size(); i++){ particles[i]->addFlockingForce(); particles[i]->addDampingForce(); particles[i]->update(); } // wrap torroidally. for (int i = 0; i < particles.size(); i++){ ofVec2f pos = particles[i]->pos; if (pos.x < 0) pos.x = ofGetWidth(); if (pos.x > ofGetWidth()) pos.x = 0; if (pos.y < 0) pos.y = ofGetHeight(); if (pos.y > ofGetHeight()) pos.y = 0; particles[i]->pos = pos; } }