[ Video ]
[ About ]
徐々に変化する文字列
Gradually changing character.
[ 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 29 30 31 |
#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) {}; void draw_blend_charactor(ofPoint point, char c1, char c2, float progress); int font_size; ofTrueTypeFont font; vector<char> charactors; int index; float progress; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); ofNoFill(); ofSetLineWidth(2); this->font_size = 130; this->font.loadFont("fonts/Kazesawa-bold.ttf", this->font_size, true, true, true); this->charactors = { 'R', 'E', 'L', 'A', 'Y' }; this->index = 0; this->progress = 0; } //-------------------------------------------------------------- void ofApp::update() { if (ofGetFrameNum() % 60 == 0) { this->index = (this->index + 1) % this->charactors.size(); this->progress = 0; } this->progress += this->progress < 100 ? 2 : 0; } //-------------------------------------------------------------- void ofApp::draw() { int tmp_index = this->index; for (int i = 0; i < this->charactors.size(); i++) { int next_index = (tmp_index + 1) % this->charactors.size(); this->draw_blend_charactor(ofPoint(144 * i + 72, ofGetHeight() * 0.5), this->charactors[tmp_index], this->charactors[next_index], this->progress); tmp_index = next_index; } } //-------------------------------------------------------------- void ofApp::draw_blend_charactor(ofPoint point, char c1, char c2, float progress) { int total_sample_count = 100; ofPushMatrix(); ofTranslate(point); ofPath path = this->font.getCharacterAsPoints(c1, true, false); vector<ofPolyline> outline = path.getOutline(); int sample_count = total_sample_count / outline.size(); vector<ofPoint> points; for (int outline_index = 0; outline_index < (int)outline.size(); outline_index++) { outline[outline_index] = outline[outline_index].getResampledByCount(sample_count); vector<glm::vec3> vertices = outline[outline_index].getVertices(); for (size_t vertices_index = 0; vertices_index < vertices.size(); vertices_index++) { ofPoint point(vertices[vertices_index].x - this->font_size * 0.5, vertices[vertices_index].y + this->font_size * 0.5, vertices[vertices_index].z); points.push_back(point); } } ofPath next_path = this->font.getCharacterAsPoints(c2, true, false); vector<ofPolyline> next_outline = next_path.getOutline(); int next_sample_count = total_sample_count / next_outline.size(); vector<ofPoint> next_points; for (int outline_index = 0; outline_index < (int)next_outline.size(); outline_index++) { next_outline[outline_index] = next_outline[outline_index].getResampledByCount(next_sample_count); vector<glm::vec3> vertices = next_outline[outline_index].getVertices(); for (size_t vertices_index = 0; vertices_index < vertices.size(); vertices_index++) { ofPoint point(vertices[vertices_index].x - this->font_size * 0.5, vertices[vertices_index].y + this->font_size * 0.5, vertices[vertices_index].z); next_points.push_back(point); } } vector<ofPoint> draw_points; for (int i = 0; i < total_sample_count; i++) { if (i < points.size() && i < next_points.size()) { ofPoint p = (next_points[i] - points[i]) * progress * 0.01 + points[i]; draw_points.push_back(p); } } for (int i = 0; i < draw_points.size(); i++) { for (int j = i + 1; j < draw_points.size(); j++) { if (draw_points[i].distance(draw_points[j]) < 15) { ofDrawLine(draw_points[i], draw_points[j]); } } } ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |