This commit is contained in:
Tobias Lindner 2019-05-23 15:52:30 +00:00
parent 247746be58
commit 6b1179c77e
3 changed files with 178 additions and 38 deletions

View File

@ -3,8 +3,7 @@
//======================================================================== //========================================================================
int main() { int main() {
ofSetupOpenGL(1000, 1000, OF_WINDOW); // <-------- setup the GL context ofSetupOpenGL(2000, 2000, OF_WINDOW);
ofRunApp(new ofApp()); ofRunApp(new ofApp());
} }
//hahahahahahahahha

View File

@ -2,6 +2,7 @@
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::setup() { void ofApp::setup() {
ofSetVerticalSync(true);
//Initialize 8 empty attractrs //Initialize 8 empty attractrs
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
@ -12,19 +13,27 @@ void ofApp::setup() {
//OSC reciever port setup //OSC reciever port setup
receiver.setup(PORT); receiver.setup(PORT);
varSystem = true;
trails = true;
history = 0.95;
//num = 1000;
//sys.assign(num, Particle());
currentMode = PARTICLE_MODE_DEFAULT;
currentModeDisp = "PARTICLE_MODE_DEFAULT";
//Black background //Black background
ofSetBackgroundColor(0, 0, 0); ofSetBackgroundColor(0, 0, 0);
ofSetFrameRate(60); ofSetFrameRate(60);
birthCount = 100;
birthCount = 0; w = ofGetWidth();
h = ofGetHeight();
//attractors.at(0)->setup(200, 200); fbo.allocate(w, h, GL_RGB);
//attractors.at(0)->setup(600, 600);
} }
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::update() { void ofApp::update() {
// *** OSC RECEIVER *** // *** OSC RECEIVER ***
while (receiver.hasWaitingMessages()) { while (receiver.hasWaitingMessages()) {
@ -57,11 +66,12 @@ void ofApp::update() {
double deltaT = ofGetLastFrameTime(); double deltaT = ofGetLastFrameTime();
birthCount += deltaT; birthCount += deltaT;
if (varSystem == true) {
//Birth control for new particles //Birth control for new particles
if (birthCount > 0.001) { if (birthCount > 0.001) {
for (int i = 0;i < 4;i++) { for (int i = 0;i < 4;i++) {
system.push_back(new Particle); system.push_back(new Particle);
system.back()->setup(ofVec2f(ofGetWidth()*.5, ofGetHeight()*.5)); system.back()->setup(currentMode);
} }
birthCount = 0; birthCount = 0;
} }
@ -70,7 +80,7 @@ void ofApp::update() {
for (int p = 0; p < system.size();) for (int p = 0; p < system.size();)
{ {
//Upate particle system /w all active attractors //Upate particle system /w all active attractors
system.at(p)->update(deltaT, &attractors); system.at(p)->update(deltaT, &attractors, system);
//Delete particles, that reached max Age //Delete particles, that reached max Age
if (system.at(p)->getAgeNorm() > 4) { if (system.at(p)->getAgeNorm() > 4) {
@ -81,19 +91,67 @@ void ofApp::update() {
p++; p++;
} }
} }
}
else {
ofSeedRandom(39);
}
} }
//--------------------------------------------------------------
void ofApp::reset() {
for (int p = 0; p < system.size();)
{
system.erase(system.begin() + p);
}
}
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::draw() { void ofApp::draw() {
if (varSystem == false) {
vector<ofVec2f> system;
for (int i = 0; i < 1000; i++) {
ofVec2f particle(ofMap(ofNoise(ofRandom(100), ofGetFrameNum() * 0.0005), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(ofRandom(100), ofGetFrameNum() * 0.0005), 0, 1, 0, ofGetHeight()));
system.push_back(particle);
}
for (int out = 0; out < system.size(); out++) {
for (int in = out + 1; in < system.size(); in++) {
if (system[out].distance(system[in]) < 60) {
ofDrawLine(system[out], system[in]);
}
}
}
for (int i = 0; i < system.size(); i++) {
ofDrawCircle(system[i], ofRandom(0.5, 3));
}
}
if (trails == true) {
fbo.begin();
ofEnableAlphaBlending(); //Enable transparency
float alpha = (1 - history) * 255;
ofSetColor(0, 0, 0, alpha);
ofFill();
ofRect(0, 0, ofGetWidth(), ofGetHeight());
ofDisableAlphaBlending(); //Disable transparency
//Draw particle system //Draw particle system
for (int p = 0; p < system.size(); p++) { for (int p = 0; p < system.size(); p++) {
system.at(p)->draw(); system.at(p)->draw();
} }
fbo.end();
}
else {
//Draw particle system
for (int p = 0; p < system.size(); p++) {
system.at(p)->draw();
}
}
//Capture time based on FrameTime //Capture time based on FrameTime
double deltaT = ofGetLastFrameTime(); double deltaT = ofGetLastFrameTime();
time += deltaT; time += deltaT;
@ -105,28 +163,91 @@ void ofApp::draw() {
time = 0; time = 0;
} }
} }
fbo.draw(0, 0);
// *** DEBUG INFO *** // *** DEBUG INFO ***
ofSetColor(230);
//All 8 Attractors with x | y coordinates //All 8 Attractors with x | y coordinates
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
//string x = ofToString(attractors.at(i)->getX()); string x = ofToString(attractors.at(i)->getX());
//string y = ofToString(attractors.at(i)->getY()); string y = ofToString(attractors.at(i)->getY());
//ofDrawBitmapString("x: " + x + " y: " + y, 100, 100 + i * 20); ofDrawBitmapString("x: " + x + " y: " + y, 100, 100 + i * 20);
} }
//Recieved OSC messages //Recieved OSC messages
//ofDrawBitmapString("OSC: " + ofToString(oscMsg),100, 275); ofDrawBitmapString("OSC: " + ofToString(oscMsg),100, 275);
//Elapsed time since last clear of attractors //Elapsed time since last clear of attractors
//ofDrawBitmapString("Time: " + ofToString(time),100, 300); ofDrawBitmapString("Time: " + ofToString(time),100, 300);
//Current FPS //Current FPS
//ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate()), 100, 325); ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate()), 100, 325);
//Current Mode
ofDrawBitmapString("Current Effect: " + currentModeDisp, 100, 350);
} }
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::keyPressed(int key) { void ofApp::keyPressed(int key) {
//Key press 1 to trigger default particle Mode
if (key == '1') {
currentMode = PARTICLE_MODE_DEFAULT;
currentModeDisp = "PARTICLE_MODE_DEFAULT";
varSystem = true;
reset();
}
//Key press 2 to trigger attractor particle Mode
if (key == '2') {
currentMode = PARTICLE_MODE_RADIAL;
currentModeDisp = "PARTICLE_MODE_RADIAL";
varSystem = true;
reset();
}
//Key press 2 to trigger rain particle Mode
if (key == '3') {
currentMode = PARTICLE_MODE_RAIN;
currentModeDisp = "PARTICLE_MODE_RAIN";
varSystem = true;
trails = false;
fbo.clear();
reset();
}
//Key press 2 to trigger attractor particle Mode
if (key == '4') {
currentMode = PARTICLE_MODE_ATTRACTOR;
currentModeDisp = "PARTICLE_MODE_ATTRACTOR";
varSystem = true;
reset();
}
//Key press 2 to trigger attractor particle Mode
if (key == '5') {
currentMode = PARTICLE_MODE_DETRACTOR;
currentModeDisp = "PARTICLE_MODE_DETRACTOR";
varSystem = true;
reset();
}
//Key press 2 to trigger attractor particle Mode
if (key == '6') {
currentMode = PARTICLE_MODE_POLY;
currentModeDisp = "PARTICLE_MODE_POLY";
varSystem = false;
trails = false;
fbo.clear();
reset();
}
if (key == '7') {
trails = true;
fbo.allocate(w, h, GL_RGB);
reset();
}
if (key == '8') {
trails = false;
fbo.clear();
reset();
}
if (key == '9') {
currentMode = PARTICLE_MODE_POLY;
currentModeDisp = "PARTICLE_MODE_BRUNIG";
varSystem = true;
reset();
}
} }
//-------------------------------------------------------------- //--------------------------------------------------------------
@ -136,6 +257,7 @@ void ofApp::keyReleased(int key) {
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y) { void ofApp::mouseMoved(int x, int y) {
attractors.at(0)->setup(ofGetMouseX(), ofGetMouseY());
} }

View File

@ -15,6 +15,7 @@ public:
void setup(); void setup();
void update(); void update();
void draw(); void draw();
void reset();
void keyPressed(int key); void keyPressed(int key);
void keyReleased(int key); void keyReleased(int key);
@ -22,23 +23,41 @@ public:
void mousePressed(int x, int y, int button); void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button); void mouseReleased(int x, int y, int button);
ofxXmlSettings default;
ofxXmlSettings attractor;
ofxXmlSettings rain;
ofxXmlSettings brunig;
private: private:
// OSC Receiver // OSC Receiver
particleMode currentMode;
string currentModeDisp;
string oscMsg; string oscMsg;
ofxOscReceiver receiver; ofxOscReceiver receiver;
float timeSent, timeReceived; float timeSent, timeReceived;
int nBlobs; int nBlobs;
int blobCount; int blobCount;
int num;
float history;
ofFbo fbo;
float xOfCentroid; float xOfCentroid;
float yOfCentroid; float yOfCentroid;
vector<Particle*> system; vector<Particle*> system;
vector<Particle>sys;
vector<Attractor*> attractors; vector<Attractor*> attractors;
float birthCount; float birthCount;
double time; double time;
bool varSystem;
bool trails;
int w;
int h;
}; };