#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(25);
ofSetWindowTitle("openFrameworks");
ofBackground(39);
ofSetLineWidth(2);
ofEnableDepthTest();
this->frame.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES);
int span = 10;
for (int x = -120; x <= 120; x += span) {
for (int y = -120; y <= 120; y += span) {
for (int z = -120; z <= 120; z += span) {
this->location_list.push_back(glm::vec3(x, y, z));
}
}
}
}
//--------------------------------------------------------------
void ofApp::update() {
ofSeedRandom(39);
this->face.clear();
this->frame.clear();
float size = 10;
for (int i = 0; i < this->location_list.size(); i++) {
this->setBoxToMesh(this->face, this->frame, this->location_list[i], size);
}
}
//--------------------------------------------------------------
void ofApp::draw() {
this->cam.begin();
ofRotateY(ofGetFrameNum() * 1.44);
this->face.draw();
this->frame.drawWireframe();
this->cam.end();
// ffmpeg -i img_%04d.jpg aaa.mp4
/*
int start = 250;
if (ofGetFrameNum() > start) {
std::ostringstream os;
os << std::setw(4) << std::setfill('0') << ofGetFrameNum() - start;
ofImage image;
image.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
image.saveImage("image/cap/img_" + os.str() + ".jpg");
if (ofGetFrameNum() - start >= 25 * 20) {
std::exit(1);
}
}
*/
}
//--------------------------------------------------------------
void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float size) {
this->setBoxToMesh(face_target, frame_target, location, size, size, size);
}
//--------------------------------------------------------------
void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float height, float width, float depth) {
auto noise_value = ofNoise(glm::vec4(location.x * 0.01, location.z * 0.01, location.y * 0.01 + ofGetFrameNum() * 0.02, ofGetFrameNum() * 0.02));
if (noise_value < 0.45) { return; }
else if (noise_value < 0.5) { noise_value = ofMap(noise_value, 0.45, 0.5, 0, 1); }
else { noise_value = 1; }
int face_index = face_target.getNumVertices();
int frame_index = frame_target.getNumVertices();
vector<glm::vec3> vertices;
vertices.push_back(glm::vec3(width * -0.5, height * 0.5, depth * -0.5));
vertices.push_back(glm::vec3(width * 0.5, height * 0.5, depth * -0.5));
vertices.push_back(glm::vec3(width * 0.5, height * 0.5, depth * 0.5));
vertices.push_back(glm::vec3(width * -0.5, height * 0.5, depth * 0.5));
vertices.push_back(glm::vec3(width * -0.5, height * -0.5, depth * -0.5));
vertices.push_back(glm::vec3(width * 0.5, height * -0.5, depth * -0.5));
vertices.push_back(glm::vec3(width * 0.5, height * -0.5, depth * 0.5));
vertices.push_back(glm::vec3(width * -0.5, height * -0.5, depth * 0.5));
for (auto& vertex : vertices) {
face_target.addVertex(location + vertex * 0.99 * noise_value);
frame_target.addVertex(location + vertex * noise_value);
}
face_target.addIndex(face_index + 0); face_target.addIndex(face_index + 1); face_target.addIndex(face_index + 2);
face_target.addIndex(face_index + 0); face_target.addIndex(face_index + 2); face_target.addIndex(face_index + 3);
face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 5); face_target.addIndex(face_index + 6);
face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 6); face_target.addIndex(face_index + 7);
face_target.addIndex(face_index + 0); face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 1);
face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 5); face_target.addIndex(face_index + 1);
face_target.addIndex(face_index + 1); face_target.addIndex(face_index + 5); face_target.addIndex(face_index + 6);
face_target.addIndex(face_index + 6); face_target.addIndex(face_index + 2); face_target.addIndex(face_index + 1);
face_target.addIndex(face_index + 2); face_target.addIndex(face_index + 6); face_target.addIndex(face_index + 7);
face_target.addIndex(face_index + 7); face_target.addIndex(face_index + 3); face_target.addIndex(face_index + 2);
face_target.addIndex(face_index + 3); face_target.addIndex(face_index + 7); face_target.addIndex(face_index + 4);
face_target.addIndex(face_index + 4); face_target.addIndex(face_index + 0); face_target.addIndex(face_index + 3);
frame_target.addIndex(frame_index + 0); frame_target.addIndex(frame_index + 1);
frame_target.addIndex(frame_index + 1); frame_target.addIndex(frame_index + 2);
frame_target.addIndex(frame_index + 2); frame_target.addIndex(frame_index + 3);
frame_target.addIndex(frame_index + 3); frame_target.addIndex(frame_index + 0);
frame_target.addIndex(frame_index + 4); frame_target.addIndex(frame_index + 5);
frame_target.addIndex(frame_index + 5); frame_target.addIndex(frame_index + 6);
frame_target.addIndex(frame_index + 6); frame_target.addIndex(frame_index + 7);
frame_target.addIndex(frame_index + 7); frame_target.addIndex(frame_index + 4);
frame_target.addIndex(frame_index + 0); frame_target.addIndex(frame_index + 4);
frame_target.addIndex(frame_index + 1); frame_target.addIndex(frame_index + 5);
frame_target.addIndex(frame_index + 2); frame_target.addIndex(frame_index + 6);
frame_target.addIndex(frame_index + 3); frame_target.addIndex(frame_index + 7);
ofColor face_color = noise_value < 1 ? ofColor(239, 39, 39) : ofColor(39);
ofColor frame_color = noise_value < 1 ? ofColor(39) : ofColor(239, 39, 39);
for (int i = 0; i < 8; i++) {
face_target.addColor(face_color);
frame_target.addColor(frame_color);
}
}
//--------------------------------------------------------------
int main() {
ofSetupOpenGL(720, 720, OF_WINDOW);
ofRunApp(new ofApp());
}