summaryrefslogtreecommitdiff
path: root/osctest/src/ofApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'osctest/src/ofApp.cpp')
-rw-r--r--osctest/src/ofApp.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/osctest/src/ofApp.cpp b/osctest/src/ofApp.cpp
new file mode 100644
index 0000000..918480e
--- /dev/null
+++ b/osctest/src/ofApp.cpp
@@ -0,0 +1,133 @@
+#include "ofApp.h"
+
+
+
+//--------------------------------------------------------------
+void ofApp::setup(){
+ ofSetVerticalSync(true);
+
+
+ gui.setup(""); // most of the time you don't need a name but don't forget to call setup
+
+ gui.add(enable.set("enable", true));
+ gui.add(duration.set("duration", 1.0f,0.0f,10.0f));
+ gui.add(spawnProbability.set("spawn", 0.1f));
+
+
+ bHide = false;
+
+}
+
+//--------------------------------------------------------------
+void ofApp::exit(){
+
+}
+
+
+//--------------------------------------------------------------
+void ofApp::update(){
+ if (ofRandom(1.0f)<(spawnProbability/ofGetFrameRate())){
+ tracers.push_back(tracer());
+ ofLog() << "new tracer: "<<tracers[tracers.size()-1].colour;
+ }
+ // open an outgoing connection to HOST:PORT
+ sender.setup(HOST, PORT);
+}
+
+//--------------------------------------------------------------
+void ofApp::draw(){
+ ofBackground(ofColor::black);
+
+ ofxOscBundle bundle;
+
+ auto t=tracers.begin();
+ while (t!=tracers.end()){
+ if (ofGetElapsedTimef()-t->born>duration){
+ tracers.erase(t);
+ }
+ else {
+ if (enable){
+ ofxOscMessage m;
+ m.setAddress("/xyrgb");
+ m.addFloatArg(t->pos.x);
+ m.addFloatArg(t->pos.y);
+ m.addIntArg(t->colour.r);
+ m.addIntArg(t->colour.g);
+ m.addIntArg(t->colour.b);
+ bundle.addMessage(m);
+ t->draw();
+ }
+ t++;
+ }
+ }
+
+ sender.sendBundle(bundle);
+
+
+ if( !bHide ){
+ gui.draw();
+ }
+}
+
+//--------------------------------------------------------------
+void ofApp::keyPressed(int key){
+ if( key == 'h' ){
+ bHide = !bHide;
+ }
+ if(key == 's') {
+ gui.saveToFile("settings.xml");
+ }
+ if(key == 'l') {
+ gui.loadFromFile("settings.xml");
+ }
+
+}
+
+//--------------------------------------------------------------
+void ofApp::keyReleased(int key){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseDragged(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void ofApp::mousePressed(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseEntered(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseExited(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::windowResized(int w, int h){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::gotMessage(ofMessage msg){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::dragEvent(ofDragInfo dragInfo){
+
+}