[ Video ]
[ About ]
雪玉。
[ 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 |
#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) {}; ofEasyCam cam; ofMesh mesh; vector<ofMeshFace> triangle_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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(25); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofSetColor(0); ofEnableDepthTest(); auto ico_sphere = ofIcoSpherePrimitive(300, 5); this->triangle_list.insert(this->triangle_list.end(), ico_sphere.getMesh().getUniqueFaces().begin(), ico_sphere.getMesh().getUniqueFaces().end()); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->mesh.clear(); for (auto radius = 150; radius <= 250; radius += 1) { for (int k = 0; k < this->triangle_list.size(); k++) { glm::vec3 avg = (this->triangle_list[k].getVertex(0) + this->triangle_list[k].getVertex(1) + this->triangle_list[k].getVertex(2)) / 3; if (ofNoise(glm::vec4(avg * 0.008, ofGetFrameNum() * 0.01)) < 0.5) { continue; } vector<glm::vec3> vertices; vertices.push_back(glm::normalize(this->triangle_list[k].getVertex(0)) * radius); vertices.push_back(glm::normalize(this->triangle_list[k].getVertex(1)) * radius); vertices.push_back(glm::normalize(this->triangle_list[k].getVertex(2)) * radius); this->mesh.addVertices(vertices); for (int i = 0; i < 3; i++) { auto noise_value = ofNoise(glm::vec4(this->triangle_list[k].getVertex(i) * 0.008, ofGetFrameNum() * 0.01)); this->mesh.addColor(ofColor(ofMap(radius, 150, 250, 0, 255), noise_value > 0.55 ? 255 : ofMap(noise_value, 0.5, 0.55, 0, 255))); } this->mesh.addTriangle(this->mesh.getNumVertices() - 1, this->mesh.getNumVertices() - 2, this->mesh.getNumVertices() - 3); } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum()); this->mesh.draw(); ofDrawSphere(150); this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |