[ 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 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 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; vector<ofColor> color_list; int color_index; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(25); ofSetWindowTitle("openFrameworks"); ofBackground(39); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 200, true, true, true); ofFbo fbo; fbo.allocate(ofGetWidth(), ofGetHeight()); fbo.begin(); ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); ofClear(0); ofSetColor(0); string word = "K&R"; font.drawString(word, font.stringWidth(word) * -0.5, font.stringHeight(word) * 0.25); fbo.end(); auto span = 5; ofPixels pixels; fbo.readToPixels(pixels); for (int x = 0; x < 720; 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)); } } } this->color_index = 0; this->color_list.push_back(ofColor(255, 255, 0)); this->color_list.push_back(ofColor(0, 255, 255)); this->color_list.push_back(ofColor(255, 0, 255)); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); ofSetColor(this->color_list[this->color_index]); if (ofGetFrameNum() % 100 == 1) { this->color_index = (this->color_index + 1) % this->color_list.size(); } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWindowSize() * 0.5); int span = 5; 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) { ofDrawLine(x + param_x, y + param_y, x + next_param_x, y + next_param_y); } else { ofFill(); ofDrawCircle(x + param_x, y + param_y, span * 0.25); } } /* int start = 201; 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); } } */ } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |