[ Video ]
[ About ]
文字の上を直進する線。
Lines on word.
[ 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 28 |
#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) {}; int number_of_agent; int len_of_tail; vector<deque<glm::vec2>> log_list; vector<glm::vec2> direction_list; ofFbo fbo; ofPixels pixels; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofTrueTypeFont font; font.loadFont("fonts/Kazesawa-bold.ttf", 250, true, true, true); this->fbo.allocate(ofGetWidth(), ofGetHeight()); this->fbo.begin(); ofClear(0); string word = "PCD"; font.drawString(word, ofGetWidth() * 0.5 - font.stringWidth(word) * 0.5, ofGetHeight() * 0.5 - font.stringHeight(word) * 0.1); word = "TOKYO"; font.drawString(word, ofGetWidth() * 0.5 - font.stringWidth(word) * 0.5, ofGetHeight() * 0.5 + font.stringHeight(word) * 1.1); this->fbo.end(); this->fbo.readToPixels(this->pixels); this->number_of_agent = 120; this->len_of_tail = 100; while (this->log_list.size() < this->number_of_agent) { int x = ofRandom(ofGetWidth()); int y = ofRandom(ofGetHeight()); if (this->pixels.getColor(x, y) != ofColor(0, 0)) { deque<glm::vec2> log; log.push_front(glm::vec2(x, y)); this->log_list.push_back(log); this->direction_list.push_back(glm::normalize(glm::vec2(ofRandom(-1, 1), ofRandom(-1, 1)))); } } ofSetLineWidth(1.5); } //-------------------------------------------------------------- void ofApp::update() { for (int i = 0; i < this->number_of_agent; i++) { glm::vec2 future = this->log_list[i].front() + this->direction_list[i] * 5; int x = future.x; int y = future.y; while (this->pixels.getColor(x, y) == ofColor(0, 0)) { this->direction_list[i] = glm::normalize(glm::vec2(ofRandom(-1, 1), ofRandom(-1, 1))); future = this->log_list[i].front() + this->direction_list[i] * 10; x = future.x; y = future.y; } this->log_list[i].push_front(future); while (this->log_list[i].size() > this->len_of_tail) { this->log_list[i].pop_back(); } } } //-------------------------------------------------------------- void ofApp::draw() { for (int i = 0; i < this->number_of_agent; i++) { ofSetColor(39); for (int l = 0; l < this->log_list[i].size() - 1; l++) { ofDrawLine(this->log_list[i][l], this->log_list[i][l + 1]); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(1280, 720, OF_WINDOW); ofRunApp(new ofApp()); } |