[ Video ]
[ About ]
Connection visualize.
[ 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) {}; glm::vec2 make_point(int len, int param); vector<ofMesh> line_list; ofMesh near_line; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetWindowTitle("openFrameworks"); ofSetFrameRate(60); ofBackground(239); ofSetColor(39); ofNoFill(); this->near_line.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->line_list.clear(); this->near_line.clear(); int len = 500; { ofMesh line; line.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); for (int param = 0; param < 100; param += 1) { line.addVertex(glm::vec3(this->make_point(len, param), 0)); if (param > 0) { line.addIndex(line.getNumVertices() - 1); line.addIndex(line.getNumVertices() - 2); } } this->line_list.push_back(line); } for (int i = 0; i < 5; i++) { ofMesh line; line.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); auto noise_seed = ofRandom(1000); for (int x = -len * 0.5; x <= len * 0.5; x += 5) { auto y = ofMap(ofNoise(noise_seed, x * 0.0035, ofGetFrameNum() * 0.0035), 0, 1, -len * 0.5, len * 0.5); line.addVertex(glm::vec3(x, y, 0)); if (x > len * -0.5) { line.addIndex(line.getNumVertices() - 1); line.addIndex(line.getNumVertices() - 2); } } this->line_list.push_back(line); } for (int i = 0; i < this->line_list.size(); i++) { for (int k = i + 1; k < this->line_list.size(); k++) { for (int m = 0; m < this->line_list[i].getNumVertices(); m++) { bool m_flag = false; int m_index = m; for (int p = 0; p < this->line_list[k].getNumVertices(); p++) { if (glm::distance(this->line_list[i].getVertex(m), this->line_list[k].getVertex(p)) < 50) { if (m_flag == false) { m_index = this->near_line.getNumVertices(); this->near_line.addVertex(this->line_list[i].getVertex(m)); m_flag = true; } this->near_line.addVertex(this->line_list[k].getVertex(p)); this->near_line.addIndex(m_index); this->near_line.addIndex(this->near_line.getNumVertices() - 1); } } } } } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); this->near_line.draw(); ofFill(); for (auto& vertex : this->near_line.getVertices()) { ofDrawCircle(vertex, 3); } ofNoFill(); ofDrawRectangle(glm::vec2(-250, -250), 500, 500); } //-------------------------------------------------------------- glm::vec2 ofApp::make_point(int len, int param) { param = param % 100; if (param < 25) { return glm::vec2(ofMap(param, 0, 25, -len * 0.5, len * 0.5), -len * 0.5); } else if (param < 50) { return glm::vec2(len * 0.5, ofMap(param, 25, 50, -len * 0.5, len * 0.5)); } else if (param < 75) { return glm::vec2(ofMap(param, 50, 75, len * 0.5, -len * 0.5), len * 0.5); } else { return glm::vec2(-len * 0.5, ofMap(param, 75, 100, len * 0.5, -len * 0.5)); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |