summaryrefslogtreecommitdiff
path: root/osctest/src/ofApp.cpp
blob: 918480e2cd56dbcbe3bde77a2dbb80f1fecf4993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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){ 
	
}