[ Video ]
[ About ]
近い点通しで線を引く。距離で透明度が変化。
Lines.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#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; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetLineWidth(1.5); ofEnableDepthTest(); this->mesh.setMode(OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->mesh.clear(); for (auto i = 0; i < 350; i++) { auto location = glm::vec3( ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0003), 0, 1, -300, 300), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0003), 0, 1, -300, 300), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0003), 0, 1, -300, 300)); this->mesh.addVertex(location); this->mesh.addColor(ofColor(255, 0)); } for (int i = 0; i < this->mesh.getVertices().size(); i++) { auto location = this->mesh.getVertex(i); vector<int> near_index_list; for (int k = 0; k < this->mesh.getVertices().size(); k++) { if (i == k) { continue; } auto other = this->mesh.getVertex(k); auto distance = glm::distance(location, other); if (distance < 50) { this->mesh.addIndex(i); this->mesh.addIndex(k); auto distance_alpha = 255; if (distance > 35) { distance_alpha = ofMap(distance, 35, 50, 255, 0); } auto i_alpha = this->mesh.getColor(i).a; this->mesh.setColor(i, ofColor(39, distance_alpha > i_alpha ? distance_alpha : i_alpha)); auto k_alpha = this->mesh.getColor(k).a; this->mesh.setColor(k, ofColor(39, distance_alpha > k_alpha ? distance_alpha : k_alpha)); } } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); for (int i = 0; i < this->mesh.getVertices().size(); i++) { ofSetColor(this->mesh.getColor(i)); ofDrawSphere(this->mesh.getVertex(i), 3); } this->mesh.draw(); this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |