Hello guys! I’m trying to write a code which draws many circles. The circles should change their brightness accordingly to the loudness of a specific frequency band which gets communicated via OSC from a Max MSP patch. The tiny circles should move all together in a circular manner around the center of the picture. By moving they should leave a trail which creates a picture, kinda like a circular spectogram.
If I have less than 60 circles, everything goes fine and it looks really good.
I’m facing the problem though, that if I want to have more than 60-70 circles it’s beginning to lag and around a 100 circle it wont even move anymore. My goal is to have 512 circles.
I’d greatly appreciate any help or hints especially because I’m not quite sure if I’m using the FBO right or if it’s even the right approach for my code.
Thank you!
void ofApp::setup(){
ofBackground(60, 60, 30);
ofSetFrameRate(25);
gui.setup();
gui.add(sineParam.set("SINE", 200.0, 0.0, 300.0));
gui.add(cosineParam.set("COSINE", 200.0, 0.0, 300.0));
gui.add(speedParam.set("SPEED", 0.5, 0.0, 3.0));
fbo.allocate(ofGetWidth(), ofGetHeight());
fbo.begin();
ofClear(255, 255, 20);
fbo.end();
receiver1.setup(PORT);
}
//--------------------------------------------------------------
void ofApp::update(){
sine = sin(ofGetElapsedTimef() * speedParam) * 200;
cosine = cos(ofGetElapsedTimef() * speedParam) * 200;
sine2 = sin(ofGetElapsedTimef() * speedParam) * 160;
cosine2 = cos(ofGetElapsedTimef() * speedParam) * 160;
for (int i = 0; i < resolution; i++)
{
sineArray[i] = (sin(ofGetElapsedTimef() * speedParam) * 298) / ((i+1)+10); //
cosArray[i] = (cos(ofGetElapsedTimef() * speedParam) * 298) / ((i+1)+10); //
}
// check for waiting messages
while(receiver1.hasWaitingMessages()){
for (int i = 0; i < resolution; i++)
{
values[i] = m.getArgAsString(i);
}
// get the next message
receiver1.getNextMessage(m);
}
}
void ofApp::draw(){
gui.draw();
fbo.draw(0, 0);
fbo.begin();
ofSetColor(0, 0, 0, 1);
for (int i = 0; i < resolution; i++)
{
ofSetColor(ofToFloat(values[i]));
ofSetCircleResolution(10);
ofDrawCircle(sineArray[i] + ofGetWidth()/2, cosArray[i]+ofGetHeight()/2, r);
}
fbo.end();
}
The relevant values from the header file:
float value;
int resolution = 60;
int r = 2;
string values[60];
float sineArray[60];
float cosArray[60];