Yes i set a matrix of circle just at the beginning and set circles color according to an image i read.
each circle is an object from a ball class i made.
// Matrix setup
void ofApp::setupMatrix() {
if (balls.size() != 0) {
balls.clear();
}
for (int y = 0; y < nbY; y++) {
for (int x = 0; x < nbX; x++) {
balls.push_back(ball());
float posx = x * ballRadius * 2;
float posy = y * ballRadius * 2;
ofColor c = image.getColor(x, y);
balls.back().setup(posx , posy, ballRadius, c);
}
}
}
then i update position of circles with some basic physics (spring effect)
// In update()
for (int i = 0; i < balls.size(); i++) {
dist = balls[i].pin - balls[i].position;
attraction = ((dist * stiffness) - (damping * dist))/mass;
balls[i].velocity = (balls[i].velocity + attraction) * friction;
balls[i].position = balls[i].position + balls[i].velocity;
if (dist.length() < limit) {
if (bTwinkle) {
balls[i].position = balls[i].pin + ofPoint(ofRandom(twinkle), ofRandom(twinkle));
}
else {
balls[i].position = balls[i].pin;
}
}
balls[i].update();
}
positions are affected by dragging the mouse
void ofApp::mouseDragged(int x, int y, int button){
for (int i = 0; i < balls.size(); i++) {
if (balls[i].inArea(x, y)) {
balls[i].position.set(x, y);
}
}
}
in draw() i make some color variation for each circle according to their position around their original position
something like a screen color blend
ofPushMatrix();
ofColor c = ofColor(ofMap(dist.x + dist.y, -10, 10, 20, 220, true));
// formula for color SCREEN blend mode
ofSetColor(ofColor(255) - (((ofColor(255) - c)*(ofColor(255) - color))/ofColor(contrast)));
ofCircle(position, radius);
ofPopMatrix();
it seems like there are heavy for loops and computations. I don’t really know if i am making it right, i think this could be done in a much better way so it could be lighter in ressources but that was the way it seemed logical for me (and my knowledge)
Now i am going to give the ofVboMesh a try, but i think it would be a good exercice for me to dig into shaders for that project…
any support is welcome !
thanks a lot @arturo