[ Video ]
[ About ]
ofMeshにランダムな座標の頂点を加えて、近接する3点のIndexを追加していく。色はX座標で変化。
Gradation triangles.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#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) {}; ofMesh mesh; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openframeworks"); ofBackground(0); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->mesh.clear(); for (int i = 0; i < 800; i++) { auto location = glm::vec3( ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.001), 0, 1, ofGetWidth() * -0.5, ofGetWidth() * 0.5), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.001), 0, 1, ofGetHeight() * -0.5, ofGetHeight() * 0.5), 0); location = glm::normalize(location) * ofRandom(200, 350); this->mesh.addVertex(location); ofColor color; color.setHsb((int)ofMap(location.x, -350, 350, 240, 240 + 255) % 255, 255, 255, 32); this->mesh.addColor(color); } for (int i = 0; i < this->mesh.getVertices().size(); i++) { auto location = this->mesh.getVertices()[i]; vector<int> near_index_list; for (int k = 0; k < this->mesh.getVertices().size(); k++) { auto other = this->mesh.getVertices()[k]; auto distance = glm::distance(location, other); if (distance < 50) { near_index_list.push_back(k); } } if (near_index_list.size() >= 3) { this->mesh.addIndex(near_index_list[0]); this->mesh.addIndex(near_index_list[1]); this->mesh.addIndex(near_index_list[2]); } } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); this->mesh.draw(); this->mesh.drawWireframe(); this->mesh.drawVertices(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |
[ Link ]
https://github.com/junkiyoshi/openFrameworks20191017