[ Video ]
[ About ]
Ring & Box.
[ 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 |
#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& line_target, glm::vec3 location, float size, ofColor face_color); void setBoxToMesh(ofMesh& face_target, ofMesh& line_target, glm::vec3 location, float height, float width, float depth, ofColor face_colorr); ofEasyCam cam; ofMesh face, line; float noise_param; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetLineWidth(2); ofEnableDepthTest(); this->line.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { this->face.clear(); this->line.clear(); for (int x = -350; x <= 350; x += 8) { for (int y = -350; y <= 350; y += 8) { auto height = ofMap(ofNoise(x, y, ofGetFrameNum() * 0.005), 0, 1, 0, 200); auto rad = std::atan2(y, x); auto noise_value = ofNoise(cos(rad), sin(rad), this->noise_param); auto radius = ofMap(noise_value, 0, 1, 100, 350); auto distance = glm::distance(glm::vec2(radius * cos(rad), radius * sin(rad)), glm::vec2(x, y)); if (distance < 50) { height *= ofMap(distance, 0, 50, 1, 0); this->setBoxToMesh(this->face, this->line, glm::vec3(x, y, height * -0.5), 8, 8, height, ofColor(239)); } else { this->setBoxToMesh(this->face, this->line, glm::vec3(x, y, -4), 8, 8, 8, ofColor(239)); } } } if (ofGetFrameNum() % 70 < 45) { this->noise_param += ofMap(ofGetFrameNum() % 70, 0, 45, 0.07, 0); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(130); this->face.draw(); ofSetColor(39); this->line.drawWireframe(); ofMesh ring, ring_line; ring_line.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); vector<glm::vec3> vertices; for (float deg = 0; deg <= 360; deg += 1) { auto noise_value = ofNoise(cos(deg * DEG_TO_RAD), sin(deg * DEG_TO_RAD), this->noise_param); auto radius = ofMap(noise_value, 0, 1, 100, 350); vertices.push_back(glm::vec3((radius - 15) * cos(deg * DEG_TO_RAD), (radius - 15) * sin(deg * DEG_TO_RAD), -300)); vertices.push_back(glm::vec3((radius + 15) * cos(deg * DEG_TO_RAD), (radius + 15) * sin(deg * DEG_TO_RAD), -300)); ring.addVertices(vertices); ring_line.addVertices(vertices); if (deg > 0) { ring.addIndex(ring.getNumVertices() - 1); ring.addIndex(ring.getNumVertices() - 2); ring.addIndex(ring.getNumVertices() - 4); ring.addIndex(ring.getNumVertices() - 1); ring.addIndex(ring.getNumVertices() - 4); ring.addIndex(ring.getNumVertices() - 5); ring_line.addIndex(ring_line.getNumVertices() - 1); ring_line.addIndex(ring_line.getNumVertices() - 3); ring_line.addIndex(ring_line.getNumVertices() - 2); ring_line.addIndex(ring_line.getNumVertices() - 4); } } ofSetColor(239); ring.draw(); ofSetColor(39); ring_line.drawWireframe(); this->cam.end(); } //-------------------------------------------------------------- void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& line_target, glm::vec3 location, float size, ofColor face_color) { this->setBoxToMesh(face_target, line_target, location, size, size, size, face_color); } //-------------------------------------------------------------- void ofApp::setBoxToMesh(ofMesh& face_target, ofMesh& line_target, glm::vec3 location, float height, float width, float depth, ofColor face_color) { int face_index = face_target.getNumVertices(); int line_index = line_target.getNumVertices(); 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(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); line_target.addVertex(location + glm::vec3(width * -0.5, height * 0.5, depth * -0.5)); line_target.addVertex(location + glm::vec3(width * 0.5, height * 0.5, depth * -0.5)); line_target.addVertex(location + glm::vec3(width * 0.5, height * 0.5, depth * 0.5)); line_target.addVertex(location + glm::vec3(width * -0.5, height * 0.5, depth * 0.5)); line_target.addVertex(location + glm::vec3(width * -0.5, height * -0.5, depth * -0.5)); line_target.addVertex(location + glm::vec3(width * 0.5, height * -0.5, depth * -0.5)); line_target.addVertex(location + glm::vec3(width * 0.5, height * -0.5, depth * 0.5)); line_target.addVertex(location + glm::vec3(width * -0.5, height * -0.5, depth * 0.5)); line_target.addIndex(line_index + 0); line_target.addIndex(line_index + 1); line_target.addIndex(line_index + 1); line_target.addIndex(line_index + 2); line_target.addIndex(line_index + 2); line_target.addIndex(line_index + 3); line_target.addIndex(line_index + 3); line_target.addIndex(line_index + 0); line_target.addIndex(line_index + 4); line_target.addIndex(line_index + 5); line_target.addIndex(line_index + 5); line_target.addIndex(line_index + 6); line_target.addIndex(line_index + 6); line_target.addIndex(line_index + 7); line_target.addIndex(line_index + 7); line_target.addIndex(line_index + 4); line_target.addIndex(line_index + 0); line_target.addIndex(line_index + 4); line_target.addIndex(line_index + 1); line_target.addIndex(line_index + 5); line_target.addIndex(line_index + 2); line_target.addIndex(line_index + 6); line_target.addIndex(line_index + 3); line_target.addIndex(line_index + 7); for (int i = 0; i < 8; i++) { face_target.addColor(face_color); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |