[ Video ]
[ About ]
矢印・文字。
[ 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 mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofTrueTypeFont font; vector<glm::vec2> location_list; void draw_arrow(glm::vec2 location, glm::vec2 next_location, float size, ofColor fill_color, ofColor no_fill_color); }; |
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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(25); ofSetWindowTitle("openFrameworks"); ofBackground(239); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 580, true, true, true); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); if (ofGetFrameNum() % 50 == 0) { this->location_list.clear(); ofFbo fbo; fbo.allocate(ofGetWidth(), ofGetHeight()); fbo.begin(); ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); ofClear(0); ofSetColor(0); string word = "!"; font.drawString(word, font.stringWidth(word) * -0.6, font.stringHeight(word) - 320); fbo.end(); auto span = 10; ofPixels pixels; fbo.readToPixels(pixels); for (int x = 60; x < 700; x += span) { for (int y = 0; y < 720; y += span) { ofColor color = pixels.getColor(x, y); if (color != ofColor(0, 0)) { this->location_list.push_back(glm::vec3(x - ofGetWidth() * 0.5, y - ofGetHeight() * 0.45, 0)); } } } } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWindowSize() * 0.5); int span = 10; auto noise_seed = glm::vec2(ofRandom(1000), ofRandom(1000)); for (auto& location : this->location_list) { auto x = location.x; auto y = location.y; auto p = ofGetFrameNum() % 100; auto next_p = (ofGetFrameNum() + 1) % 100; auto param = p < 25 ? 0 : p < 50 ? ofMap(p, 25, 50, 0, 1) : p < 75 ? 1 : ofMap(p, 75, 100, 1, 0); auto next_param = next_p < 25 ? 0 : next_p < 50 ? ofMap(next_p, 25, 50, 0, 1) : next_p < 75 ? 1 : ofMap(next_p, 75, 100, 1, 0); auto param_x = ofMap(ofNoise(noise_seed.x, x * 0.1, y * 0.1, ofGetFrameNum() * 0.01), 0, 1, -720, 720) * param; auto param_y = ofMap(ofNoise(noise_seed.y, x * 0.1, y * 0.1, ofGetFrameNum() * 0.01), 0, 1, -720, 720) * param; auto next_param_x = ofMap(ofNoise(noise_seed.x, x * 0.1, y * 0.1, (ofGetFrameNum() + 1) * 0.01), 0, 1, -720, 720) * next_param; auto next_param_y = ofMap(ofNoise(noise_seed.y, x * 0.1, y * 0.1, (ofGetFrameNum() + 1) * 0.01), 0, 1, -720, 720) * next_param; if (param > 0) { this->draw_arrow(glm::vec2(x + param_x, y + param_y), glm::vec2(x + next_param_x, y + next_param_y), span * 1.2, ofColor(39), ofColor(39, 39, 239)); } else { ofSetColor(39); ofFill(); ofDrawCircle(x + param_x, y + param_y, span * 0.35); ofSetColor(39, 39, 239); ofNoFill(); ofDrawCircle(x + param_x, y + param_y, span * 0.35); } } /* int start = 100; if (ofGetFrameNum() > start) { ostringstream os; os << setw(4) << setfill('0') << ofGetFrameNum() - start; ofImage image; image.grabScreen(0, 0, ofGetWidth(), ofGetHeight()); image.saveImage("image/cap/img_" + os.str() + ".jpg"); if (ofGetFrameNum() - start >= 25 * 20) { std::exit(1); } } */ } //-------------------------------------------------------------- void ofApp::draw_arrow(glm::vec2 location, glm::vec2 next_location, float size, ofColor fill_color, ofColor no_fill_color) { auto angle = std::atan2(next_location.y - location.y, next_location.x - location.x); ofSetColor(fill_color); ofFill(); ofBeginShape(); ofVertex(glm::vec2(size * 0.8 * cos(angle), size * 0.8 * sin(angle)) + location); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) + location); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) + location); ofEndShape(true); ofBeginShape(); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.25 + location); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.25 - glm::vec2(size * cos(angle), size * sin(angle)) * 0.5 + location); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.25 - glm::vec2(size * cos(angle), size * sin(angle)) * 0.5 + location); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.25 + location); ofEndShape(true); ofSetColor(no_fill_color); ofNoFill(); ofBeginShape(); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.25 + location); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) + location); ofVertex(glm::vec2(size * 0.8 * cos(angle), size * 0.8 * sin(angle)) + location); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) + location); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.25 + location); ofEndShape(); ofBeginShape(); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.25 + location); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.25 - glm::vec2(size * cos(angle), size * sin(angle)) * 0.5 + location); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.25 - glm::vec2(size * cos(angle), size * sin(angle)) * 0.5 + location); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.25 + location); ofEndShape(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |