[ Video ]
[ About ]
球体上座標を移動するエージェントと関連性の可視化
Agents moving on sphere coordinate. Visualize friendship.
[ 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 |
#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 draw_sphere(glm::vec3 location, float radius, ofColor color); ofEasyCam cam; }; |
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 |
#pragma once #include "ofMain.h" <pre class="lang:default decode:true " title="ofApp.cpp" >#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(39); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); this->draw_sphere(glm::vec3(-250, 0, 0), 450, ofColor(239)); this->draw_sphere(glm::vec3(500, 500, 0), 200, ofColor(239, 0, 0)); this->draw_sphere(glm::vec3(500, 0, 0), 200, ofColor(0, 239, 0)); this->draw_sphere(glm::vec3(500, -500, 0), 200, ofColor(0, 0, 239)); this->cam.end(); } //-------------------------------------------------------------- void ofApp::draw_sphere(glm::vec3 location, float radius, ofColor color) { vector<glm::vec3> locations; for (int i = 0; i < 120; i++) { glm::vec3 random_location = glm::vec3( ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0015), 0, 1, -1, 1), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0015), 0, 1, -1, 1), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.0015), 0, 1, -1, 1) ); glm::vec3 l = glm::normalize(random_location) * radius; locations.push_back(l + location); } for (int out_index = 0; out_index < locations.size(); out_index++) { ofSetColor(color); ofDrawSphere(locations[out_index], 5); vector<glm::vec3> near_locations; for (int in_index = 0; in_index < locations.size(); in_index++) { if (glm::length(locations[out_index] - locations[in_index]) < radius * 0.25) { ofDrawLine(locations[out_index], locations[in_index]); near_locations.push_back(locations[in_index]); } } if (near_locations.size() > 3) { for (int i = 0; i < near_locations.size() - 2; i++) { ofSetColor(color, 200); ofBeginShape(); ofVertex(near_locations[i]); ofVertex(near_locations[i + 1]); ofVertex(near_locations[i + 2]); ofEndShape(true); } } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |