[ Video ]
[ About ]
ランダムウォークが近づいたらボックスの描写をやめる。
時間経過で再描写する。
Stop describing the box when the random walk approaches.
Redescribe it over time.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#pragma once #include "ofMain.h" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key) {}; void keyReleased(int key) {}; void mouseMoved(int x, int y) {}; void mouseDragged(int x, int y, int button) {}; void mousePressed(int x, int y, int button) {}; void mouseReleased(int x, int y, int button) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; void setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float size, ofColor color); void setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float height, float width, float depth, ofColor color); ofEasyCam cam; ofMesh face, frame; vector<glm::vec3> log_list; float len; vector<glm::vec3> box_location_list; vector<float> alpah_param_list; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(0); ofEnableDepthTest(); ofTrueTypeFont font; int font_size = 120; font.loadFont("fonts/Kazesawa-Bold.ttf", font_size, true, true, true); ofFbo fbo; fbo.allocate(ofGetWidth(), ofGetHeight()); fbo.begin(); ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); ofClear(0); ofSetColor(0); string word = "BREAK"; for (int y = -180; y <= 180; y += 180) { font.drawString(word, font.stringWidth(word) * -0.5, y + font.stringHeight(word) * 0.5); } fbo.end(); this->len = 5; ofPixels pixels; fbo.readToPixels(pixels); for (int x = 0; x < fbo.getWidth(); x += this->len) { for (int y = 0; y < fbo.getHeight(); y += this->len) { ofColor color = pixels.getColor(x, y); if (color != ofColor(0, 0)) { for (int z = this->len * -2; z <= this->len * 2; z += this->len) { this->box_location_list.push_back(glm::vec3(x, y, z)); this->alpah_param_list.push_back(255); } } } } this->frame.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->face.clear(); this->frame.clear(); auto noise_seed = glm::vec3(ofRandom(1000), ofRandom(1000), ofRandom(1000)); auto noise_location = glm::vec3(ofMap(ofNoise(noise_seed.x, ofGetFrameNum() * 0.005), 0, 1, 50, 670), ofMap(ofNoise(noise_seed.y, ofGetFrameNum() * 0.005), 0, 1, 50, 670), ofMap(ofNoise(noise_seed.z, ofGetFrameNum() * 0.005), 0, 1, -25, 25)); this->log_list.push_back(noise_location); while (this->log_list.size() > 30) { this->log_list.erase(this->log_list.begin()); } for (int i = 0; i < this->box_location_list.size(); i++) { if (glm::distance(this->box_location_list[i], noise_location) < 30) { this->alpah_param_list[i] = 0; } if (this->alpah_param_list[i] > 200) { this->setBoxToMesh(this->face, this->frame, this->box_location_list[i], this->len, ofColor(239, ofMap(this->alpah_param_list[i], 200, 255, 0, 255))); } this->alpah_param_list[i] = this->alpah_param_list[i] >= 255 ? 255 : this->alpah_param_list[i] + 1.5; } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(180); ofTranslate(ofGetWidth() * -0.5, ofGetHeight() * -0.5); ofNoFill(); ofBeginShape(); ofVertices(this->log_list); ofEndShape(); ofFill(); ofDrawSphere(this->log_list.back(), 5); this->face.drawFaces(); this->frame.drawWireframe(); this->cam.end(); } //-------------------------------------------------------------- void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float size, ofColor color) { this->setBoxToMesh(face_target, frame_target, location, size, size, size, color); } //-------------------------------------------------------------- void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& frame_target, glm::vec3 location, float height, float width, float depth, ofColor color) { 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(color); frame_target.addColor(ofColor(39)); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |