[ Video ]
[ About ]
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 "ofFbo.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) {}; ofEasyCam cam; ofTrueTypeFont font; void draw_water(); void draw_sand(); void draw_fish(ofPoint location); }; |
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofBackground(239); ofSetWindowTitle("Insta"); ofEnableDepthTest(); this->font.loadFont("fonts/Kazesawa-Extrabold.ttf", 50, true, false, true); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(180); this->draw_water(); this->draw_sand(); for (int i = 0; i < 15; i++) { float param_1 = ofRandom(1000); float param_2 = ofRandom(0.005, 0.008); this->draw_fish(ofPoint( ofMap(ofNoise(param_1 * 0.1, ofGetFrameNum() * param_2), 0, 1, -ofGetWidth() / 2, ofGetWidth() /2), ofMap(ofNoise(param_1 * 0.3, ofGetFrameNum() * param_2), 0, 1, -ofGetHeight() / 2, ofGetHeight() / 2), ofMap(ofNoise(param_1 * 0.9, ofGetFrameNum() * param_2), 0, 1, 100, ofGetHeight() - 100) )); } this->cam.end(); } //-------------------------------------------------------------- void ofApp::draw_water() { ofSetColor(0, 0, 139); std::string words = "Water"; ofPoint words_size = ofPoint(this->font.stringWidth(words), this->font.stringHeight(words)); std::vector<ofTTFCharacter> paths = this->font.getStringAsPoints(words); for (int x = -ofGetWidth() / 2; x < ofGetWidth() / 2; x += words_size.x) { for (int y = -ofGetHeight() / 2; y < ofGetHeight() / 2; y += words_size.y) { ofPoint words_center(x + words_size.x / 2, y - words_size.y / 2); for (int p_index = 0; p_index < paths.size(); p_index++) { vector<ofPolyline> outline = paths[p_index].getOutline(); std::vector<ofPoint> points; for (int o_index = 0; o_index < outline.size(); o_index++) { if (o_index > 0) { ofNextContour(true); } outline[o_index] = outline[o_index].getResampledBySpacing(1); vector<ofPoint> vertices = outline[o_index].getVertices(); for (int v_index = 0; v_index < vertices.size(); v_index++) { ofPoint point = vertices[v_index] - words_center; float z = ofMap(ofNoise(point.x * 0.005, point.y * 0.005, ofGetFrameNum() * 0.005), 0, 1, 0, 80); points.push_back(point + ofPoint(0, 0, z)); } } if (points.size() > 0) { ofBeginShape(); ofVertices(points); ofEndShape(true); } } } } } //-------------------------------------------------------------- void ofApp::draw_sand() { ofSetColor(39, 0, 0); std::string words = "Sand"; ofPoint words_size = ofPoint(this->font.stringWidth(words), this->font.stringHeight(words)); std::vector<ofTTFCharacter> paths = this->font.getStringAsPoints(words); for (int x = -ofGetWidth() / 2; x < ofGetWidth() / 2; x += words_size.x) { for (int y = -ofGetHeight() / 2; y < ofGetHeight() / 2; y += words_size.y) { ofPoint words_center(x + words_size.x / 2, y - words_size.y / 2); for (int p_index = 0; p_index < paths.size(); p_index++) { vector<ofPolyline> outline = paths[p_index].getOutline(); std::vector<ofPoint> points; for (int o_index = 0; o_index < outline.size(); o_index++) { if (o_index > 0) { ofNextContour(true); } outline[o_index] = outline[o_index].getResampledBySpacing(1); vector<ofPoint> vertices = outline[o_index].getVertices(); for (int v_index = 0; v_index < vertices.size(); v_index++) { ofPoint point = vertices[v_index] - words_center; float z = ofMap(ofNoise(point.x * 0.001, point.y * 0.001), 0, 1, 0, 80) + ofGetHeight(); points.push_back(point + ofPoint(0, 0, z)); } } if (points.size() > 0) { ofBeginShape(); ofVertices(points); ofEndShape(true); } } } } } //-------------------------------------------------------------- void ofApp::draw_fish(ofPoint location) { ofPushMatrix(); ofTranslate(location); ofRotateX(90); std::string words = "Fish"; ofPoint words_size = ofPoint(this->font.stringWidth(words), this->font.stringHeight(words)); std::vector<ofTTFCharacter> paths = this->font.getStringAsPoints(words); ofColor fish_color; fish_color.setHsb(ofRandom(255), 239, 239); ofSetColor(fish_color); for (int p_index = 0; p_index < paths.size(); p_index++) { vector<ofPolyline> outline = paths[p_index].getOutline(); std::vector<ofPoint> points; for (int o_index = 0; o_index < outline.size(); o_index++) { if (o_index > 0) { ofNextContour(true); } outline[o_index] = outline[o_index].getResampledBySpacing(1); vector<ofPoint> vertices = outline[o_index].getVertices(); for (int v_index = 0; v_index < vertices.size(); v_index++) { points.push_back(vertices[v_index]); } } if (points.size() > 0) { ofBeginShape(); ofVertices(points); ofEndShape(true); } } ofPopMatrix(); } //======================================================================== int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |