#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(60);
ofSetWindowTitle("openFrameworks");
ofBackground(255);
ofSetLineWidth(0.5);
ofEnableDepthTest();
ofFbo fbo;
fbo.allocate(ofGetWidth(), ofGetHeight());
fbo.begin();
ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5);
ofClear(0);
ofSetColor(0);
ofTrueTypeFont font;
font.loadFont("fonts/Kazesawa-Bold.ttf", 240, true, true, true);
string word = "FIRE";
font.drawString(word, font.stringWidth(word) * -0.5, font.stringHeight(word));
fbo.end();
auto span = 10;
ofPixels pixels;
fbo.readToPixels(pixels);
for (int x = 0; x < fbo.getWidth(); x += span) {
for (int y = 0; y < fbo.getHeight(); y += span) {
ofColor color = pixels.getColor(x, y);
if (color != ofColor(0, 0)) {
for (int z = span * -10; z <= span * 10; z += span) {
this->location_list.push_back(glm::vec3(x - ofGetWidth() * 0.5, ofGetHeight() - y - ofGetHeight() * 0.3, z));
}
}
}
}
for (int x = 0; x < fbo.getWidth(); x += span) {
for (int y = fbo.getHeight() * 0.3; y < fbo.getHeight(); y += span) {
this->location_list.push_back(glm::vec3(x - ofGetWidth() * 0.5, ofGetHeight() - y - ofGetHeight() * 0.3, -110));
}
}
this->line.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES);
}
//--------------------------------------------------------------
void ofApp::update() {
this->face.clear();
this->line.clear();
for (int i = 0; i < this->location_list.size(); i++) {
auto noise_value = ofNoise(this->location_list[i].x * 0.008, this->location_list[i].y * 0.008, this->location_list[i].z * 0.008 - ofGetFrameNum() * 0.03);
if (this->location_list[i].z == -110 || noise_value < ofMap(this->location_list[i].z, -100, 100, 0.8, 0.1)) {
this->setBoxToMesh(this->face, this->line, this->location_list[i], 10, 10, 10);
}
}
}
//--------------------------------------------------------------
void ofApp::draw() {
this->cam.begin();
ofRotateX(-90);
ofRotateZ(ofGetFrameNum() * 0.6666666666666666);
ofSetColor(255);
this->face.draw();
ofSetColor(0);
this->line.draw();
this->cam.end();
}
//--------------------------------------------------------------
void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float height, float width, float depth) {
int index = face_target.getVertices().size();
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.99, height * 0.5 * 0.99, depth * -0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.99, height * 0.5 * 0.99, depth * -0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.99, height * 0.5 * 0.99, depth * 0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.99, height * 0.5 * 0.99, depth * 0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.99, height * -0.5 * 0.99, depth * -0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.99, height * -0.5 * 0.99, depth * -0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * 0.5 * 0.99, height * -0.5 * 0.99, depth * 0.5 * 0.99));
face_target.addVertex(location + glm::vec3(width * -0.5 * 0.99, height * -0.5 * 0.99, depth * 0.5 * 0.99));
face_target.addIndex(index + 0); face_target.addIndex(index + 1); face_target.addIndex(index + 2);
face_target.addIndex(index + 0); face_target.addIndex(index + 2); face_target.addIndex(index + 3);
face_target.addIndex(index + 4); face_target.addIndex(index + 5); face_target.addIndex(index + 6);
face_target.addIndex(index + 4); face_target.addIndex(index + 6); face_target.addIndex(index + 7);
face_target.addIndex(index + 0); face_target.addIndex(index + 4); face_target.addIndex(index + 1);
face_target.addIndex(index + 4); face_target.addIndex(index + 5); face_target.addIndex(index + 1);
face_target.addIndex(index + 1); face_target.addIndex(index + 5); face_target.addIndex(index + 6);
face_target.addIndex(index + 6); face_target.addIndex(index + 2); face_target.addIndex(index + 1);
face_target.addIndex(index + 2); face_target.addIndex(index + 6); face_target.addIndex(index + 7);
face_target.addIndex(index + 7); face_target.addIndex(index + 3); face_target.addIndex(index + 2);
face_target.addIndex(index + 3); face_target.addIndex(index + 7); face_target.addIndex(index + 4);
face_target.addIndex(index + 4); face_target.addIndex(index + 0); face_target.addIndex(index + 3);
frame_target.addVertex(location + glm::vec3(width * -0.5, height * 0.5, depth * -0.5));
frame_target.addVertex(location + glm::vec3(width * 0.5, height * 0.5, depth * -0.5));
frame_target.addVertex(location + glm::vec3(width * 0.5, height * 0.5, depth * 0.5));
frame_target.addVertex(location + glm::vec3(width * -0.5, height * 0.5, depth * 0.5));
frame_target.addVertex(location + glm::vec3(width * -0.5, height * -0.5, depth * -0.5));
frame_target.addVertex(location + glm::vec3(width * 0.5, height * -0.5, depth * -0.5));
frame_target.addVertex(location + glm::vec3(width * 0.5, height * -0.5, depth * 0.5));
frame_target.addVertex(location + glm::vec3(width * -0.5, height * -0.5, depth * 0.5));
frame_target.addIndex(index + 0); frame_target.addIndex(index + 1);
frame_target.addIndex(index + 1); frame_target.addIndex(index + 2);
frame_target.addIndex(index + 2); frame_target.addIndex(index + 3);
frame_target.addIndex(index + 3); frame_target.addIndex(index + 0);
frame_target.addIndex(index + 4); frame_target.addIndex(index + 5);
frame_target.addIndex(index + 5); frame_target.addIndex(index + 6);
frame_target.addIndex(index + 6); frame_target.addIndex(index + 7);
frame_target.addIndex(index + 7); frame_target.addIndex(index + 4);
frame_target.addIndex(index + 0); frame_target.addIndex(index + 4);
frame_target.addIndex(index + 1); frame_target.addIndex(index + 5);
frame_target.addIndex(index + 2); frame_target.addIndex(index + 6);
frame_target.addIndex(index + 3); frame_target.addIndex(index + 7);
for (int i = 0; i < 8; i++) {
face_target.addColor(ofColor(location.z < 0 ? 0 : ofMap(location.z, 0, 100, 0, 255)));
frame_target.addColor(ofColor(255));
}
}
//--------------------------------------------------------------
int main() {
ofSetupOpenGL(720, 720, OF_WINDOW);
ofRunApp(new ofApp());
}