[ Video ]
[ About ]
目に見えないエージェントの軌跡を可視化
Visualize log of invisible agents.
[ 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 26 27 |
#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) {}; float len_min; float len_max; vector<glm::vec2> agent_locations; vector<glm::vec2> rect_locations; vector<vector<float>> rect_lens; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(39); ofSetColor(39); ofNoFill(); ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); this->len_min = 14; this->len_max = 72; for (int x = this->len_max * 0.5; x < ofGetWidth(); x += this->len_max) { for (int y = this->len_max * 0.5; y < ofGetHeight(); y += this->len_max) { this->rect_locations.push_back(glm::vec2(x, y)); } } for (int i = 0; i < this->rect_locations.size(); i++) { vector<float> rect_len; this->rect_lens.push_back(rect_len); } } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->agent_locations.clear(); for (int i = 0; i < 8; i++) { agent_locations.push_back(glm::vec2( ofMap(ofNoise(ofRandom(10000), ofGetFrameNum() * 0.005), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(ofRandom(10000), ofGetFrameNum() * 0.005), 0, 1, 0, ofGetHeight()) )); } for (int i = 0; i < this->rect_locations.size(); i++) { for (int l = this->rect_lens[i].size() - 1; l > -1; l--) { this->rect_lens[i][l] += 3; if (this->rect_lens[i][l] > this->len_max) { this->rect_lens[i].erase(this->rect_lens[i].begin() + l); } } } for (int i = 0; i < this->agent_locations.size(); i++) { for (int rect_index = 0; rect_index < this->rect_locations.size(); rect_index++) { if (this->agent_locations[i].x > this->rect_locations[rect_index].x - this->len_max * 0.5 && this->agent_locations[i].x < this->rect_locations[rect_index].x + this->len_max * 0.5 && this->agent_locations[i].y > this->rect_locations[rect_index].y - this->len_max * 0.5 && this->agent_locations[i].y < this->rect_locations[rect_index].y + this->len_max * 0.5) { this->rect_lens[rect_index].push_back(this->len_min); } } } } //-------------------------------------------------------------- void ofApp::draw() { ofNoFill(); for (int i = 0; i < this->rect_locations.size(); i++) { for (int l = this->rect_lens[i].size() - 1; l > -1; l--) { ofSetColor(239); ofDrawRectangle(this->rect_locations[i], this->rect_lens[i][l], this->rect_lens[i][l]); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |