#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { //Initialize 8 empty attractrs for (int i = 0; i < 8; i++) { attractors.push_back(new Attractor); } //OSC reciever port setup receiver.setup(PORT); //Black background ofSetBackgroundColor(0, 0, 0); ofSetFrameRate(60); birthCount = 0; //attractors.at(0)->setup(200, 200); } //-------------------------------------------------------------- void ofApp::update() { // *** OSC RECEIVER *** while (receiver.hasWaitingMessages()) { ofxOscMessage contourCentroids; receiver.getNextMessage(&contourCentroids); oscMsg = ofToString(contourCentroids); //Get active ammount of attractors (nBlobs) and their x & y coordinates //Exp. OSC Message: " /centroidsOfBlob ammount xValue, yValue" if (contourCentroids.getAddress() == "/centroidsOfBlob") { nBlobs = contourCentroids.getArgAsInt(0); for (int i = 1; i <= nBlobs; i++) { xOfCentroid = contourCentroids.getArgAsFloat(i * 2 - 1) * ofGetWindowWidth(); yOfCentroid = contourCentroids.getArgAsFloat(i * 2) * ofGetWindowHeight(); attractors.at(i - 1)->setup(xOfCentroid, yOfCentroid); } } //Delete all Attractors on command if (contourCentroids.getAddress() == "/checkin") { for (int i = 0; i < 8; i++) { attractors.at(i)->setup(0, 0); } } } // *** PARTICLE EMITTER *** //Capture time based on FrameTime double deltaT = ofGetLastFrameTime(); birthCount += deltaT; //Birth control for new particles if (birthCount > 0.001) { for (int i = 0;i < 4;i++) { system.push_back(new thParticle); system.back()->setup(ofVec2f(ofGetWidth()*.5, ofGetHeight()*.5)); } birthCount = 0; } for (int p = 0; p < system.size();) { //Upate particle system /w all active attractors system.at(p)->update(deltaT, &attractors); //Delete particles, that reached max Age if (system.at(p)->getAgeNorm() > 4) { delete system.at(p); system.erase(system.begin() + p); } else { p++; } } } //-------------------------------------------------------------- void ofApp::draw() { //Draw particle system for (int p = 0; p < system.size(); p++) { system.at(p)->draw(); } //Capture time based on FrameTime double deltaT = ofGetLastFrameTime(); time += deltaT; // Delete inactive attractors after 4 seconds based on Frametime if (time > 2) { for (int i = 0; i < 8; i++) { //attractors.at(i)->setup(0, 0); time = 0; } } // *** DEBUG INFO *** //All 8 Attractors with x | y coordinates for (int i = 0; i < 8; i++) { //string x = ofToString(attractors.at(i)->getX()); //string y = ofToString(attractors.at(i)->getY()); //ofDrawBitmapString("x: " + x + " y: " + y, 100, 100 + i * 20); } //Recieved OSC messages //ofDrawBitmapString("OSC: " + ofToString(oscMsg),100, 275); //Elapsed time since last clear of attractors //ofDrawBitmapString("Time: " + ofToString(time),100, 300); //Current FPS //ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate()), 100, 325); } //-------------------------------------------------------------- void ofApp::keyPressed(int key) { } //-------------------------------------------------------------- void ofApp::keyReleased(int key) { } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y) { } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button) { } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button) { }