[ Video ]
[ About ]
箱の上の文字波紋。
Ripple of font on the box.
[ 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 32 33 |
#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) {}; ofEasyCam cam; int font_size; int len; vector<ofPath> chara_path; vector<int> chara_index; vector<int> face_index; vector<glm::vec3> location; vector<int> 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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofNoFill(); ofSetLineWidth(3); this->font_size = 200; ofTrueTypeFont font; font.loadFont("fonts/Kazesawa-Bold.ttf", this->font_size, true, true, true); for (char c = 'A'; c <= 'Z'; c++) { this->chara_path.push_back(font.getCharacterAsPoints(c, true, false)); } this->len = 300; for (int i = 0; i < 80; i++) { this->chara_index.push_back((int)ofRandom(this->chara_path.size())); this->face_index.push_back((int)ofRandom(6)); this->location.push_back(glm::vec3(ofRandom(-this->len * 0.5, this->len * 0.5), ofRandom(-this->len * 0.5, this->len * 0.5), this->len * 0.5)); this->progress.push_back((int)ofRandom(100)); } } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum() * 0.8); for (int i = 0; i < this->chara_index.size(); i++) { this->progress[i] = (this->progress[i] + 1) % 100; if (this->progress[i] == 0) { this->chara_index[i] = ((int)ofRandom(this->chara_path.size())); this->face_index[i] = ((int)ofRandom(6)); this->location[i] = (glm::vec3(ofRandom(-this->len * 0.5, this->len * 0.5), ofRandom(-this->len * 0.5, this->len * 0.5), this->len * 0.5)); continue; } ofPushMatrix(); if (this->face_index[i] < 4) { ofRotateX(this->face_index[i] * 90); } else if(this->face_index[i] < 5) { ofRotateY(90); } else { ofRotateY(270); } auto alpha = 255; if (this->progress[i] > 50) { alpha = ofMap(this->progress[i], 50, 100, 255, 0); } ofSetColor(39, alpha); ofBeginShape(); auto outline = this->chara_path[this->chara_index[i]].getOutline(); ofBeginShape(); for (int line_index = 0; line_index < outline.size(); line_index++) { if (line_index != 0) { ofNextContour(true); } auto vertices = outline[line_index].getVertices(); for (int vertices_index = 0; vertices_index < vertices.size(); vertices_index++) { auto point = this->location[i] + (vertices[vertices_index] / 100 * this->progress[i]) + glm::vec2(this->font_size / 100 * this->progress[i] * -0.5, this->font_size / 100 * this->progress[i] * 0.5); if (point.y > this->len * 0.5) { point.y = this->len * 0.5; } if (point.y < -this->len * 0.5) { point.y = -this->len * 0.5; } if (point.x > this->len * 0.5) { point.x = this->len * 0.5; } if (point.x < -this->len * 0.5) { point.x = -this->len * 0.5; } ofVertex(point); } } ofEndShape(true); ofPopMatrix(); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |