[ Video ]
[ About ]
ofxTrueTypeFontUCでせっかく日本語が扱えるにようになったのに全然触っていなかったので遊んでみました。ofxTrueTypeFontUCのgetStringAsPoints関数から文字の座標を取得して、全ての座標を原点から同じ距離にしてあります。
Z軸も少しズラしてあるので球体に張り付いた文字のような形になってくれました。文字が大きいビリヤードボールのような形ですね。
動画をシェアしているSNS(Instagram/Twitter)のフォロワーは基本外国の方が多いですが、ひらがなが文字という事に気づいてくれるだろうか…(笑
[ 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" #include "ofxTrueTypeFontUC/src/ofxTrueTypeFontUC.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) {}; // Make Member ofEasyCam cam; ofxTrueTypeFontUC font; // Make Method void draw_character_sphere(ofPoint point, string word, int radius); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(239); ofSetWindowTitle("Insta"); ofEnableDepthTest(); ofSetColor(39); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 150, true, true); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { vector<vector<string>> words = { { "あ", "い", "う", "え", "お" }, { "か", "き", "く", "け", "こ" }, { "さ", "し", "す", "せ", "そ" }, { "た", "ち", "つ", "て", "と" }, { "な", "に", "ぬ", "ね", "の" }, }; this->cam.begin(); ofRotateX(180); int span = 144; for (int y = 0; y < words.size(); y++) { for (int x = 0; x < words[y].size(); x++) { this->draw_character_sphere(ofPoint(x * span - ofGetWidth() / 2 + span / 2, y * span - ofGetHeight() / 2 + span / 2), words[y][x], 80); } } this->cam.end(); } //-------------------------------------------------------------- void ofApp::draw_character_sphere(ofPoint point, string word, int radius) { ofPoint word_size = ofPoint(this->font.stringWidth(word), this->font.stringHeight(word)); vector<ofTTFCharacter> word_paths = this->font.getStringAsPoints(word); ofPoint start, end; ofPushMatrix(); ofTranslate(point); int deg_param = ofGetFrameNum() % 1080; if (deg_param > 720) { ofRotateY(deg_param - 720); } else if (deg_param > 360) { ofRotateZ(deg_param - 360); } else { ofRotateX(deg_param); } for (int w_index = 0; w_index < word_paths.size(); w_index++) { vector<ofPolyline> outline = word_paths[w_index].getOutline(); ofVec3f center = outline[0].getCentroid2D(); for (int o_index = 0; o_index < outline.size(); o_index++) { outline[o_index] = outline[o_index].getResampledBySpacing(3); vector<ofPoint> vertices = outline[o_index].getVertices(); for (int v_index = 1; v_index < vertices.size(); v_index++) { start = ofPoint(vertices[v_index - 1].x - word_size.x / 2, vertices[v_index - 1].y + word_size.y / 2, -radius); end = ofPoint(vertices[v_index].x - word_size.x / 2, vertices[v_index].y + word_size.y / 2, -radius); ofDrawLine(start.normalized() * radius, end.normalized() * radius); } start = ofPoint(vertices[0].x - word_size.x / 2, vertices[0].y + word_size.y / 2, -radius); end = ofPoint(vertices[vertices.size() - 1].x - word_size.x / 2, vertices[vertices.size() - 1].y + word_size.y / 2, -radius); ofDrawLine(start.normalized() * radius, end.normalized() * radius); } } ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |