[ Video ]
[ About ]
文字の波紋。
Ripple of ASCII.
[ 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" #include "Ripple.h" #include "opencv2/opencv.hpp" 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) {}; ofTrueTypeFont font; vector<string> word_list; vector<unique_ptr<Ripple>> ripple_list; ofFbo fbo; ofPixels pixels; cv::Mat pixels_mat; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); ofNoFill(); ofTrueTypeFontSettings font_settings("fonts/msgothic.ttc", 20); font_settings.antialiased = true; font_settings.addRanges(ofAlphabet::Japanese); this->font.load(font_settings); this->word_list = { u8"!", u8"#", u8"$", u8"%", u8"&", u8"'", u8"(", u8")", u8"*", u8"+", u8",", u8"-", u8".", u8"/", u8"0", u8"1", u8"2", u8"3", u8"4", u8"5", u8"6", u8"7", u8"8", u8"9", u8"0", u8":", u8";", u8"<", u8"=", u8">", u8"?", u8"@", u8"A", u8"B", u8"C", u8"D", u8"E", u8"F", u8"G", u8"H", u8"I", u8"J", u8"K", u8"L", u8"M", u8"N", u8"O", u8"P", u8"Q", u8"R", u8"S", u8"T", u8"U", u8"V", u8"W", u8"X", u8"Y", u8"Z", u8"a", u8"b", u8"c", u8"d", u8"e", u8"f", u8"g", u8"h", u8"i", u8"j", u8"k", u8"l", u8"m", u8"n", u8"o", u8"p", u8"q", u8"r", u8"s", u8"t", u8"u", u8"v", u8"w", u8"x", u8"y", u8"z", u8"ア", u8"イ", u8"ウ", u8"エ", u8"オ", u8"カ", u8"キ", u8"ク", u8"ケ", u8"コ", u8"サ", u8"シ", u8"ス", u8"セ", u8"ソ", u8"タ", u8"チ", u8"ツ", u8"テ", u8"ト", u8"ナ", u8"ニ", u8"ヌ", u8"ネ", u8"ノ", u8"ハ", u8"ヒ", u8"フ", u8"ヘ", u8"ホ", u8"マ", u8"ミ", u8"ム", u8"メ", u8"モ", u8"ヤ", u8"ユ", u8"ヨ", u8"ラ", u8"リ", u8"ル", u8"レ", u8"ロ", u8"ワ", u8"ヲ", u8"ン", }; this->fbo.allocate(ofGetWidth() + 25, ofGetHeight() + 25); this->fbo.readToPixels(this->pixels); this->pixels_mat = cv::Mat(this->pixels.getHeight(), this->pixels.getWidth(), CV_8UC4, this->pixels.getData()); } //-------------------------------------------------------------- void ofApp::update() { if (ofGetFrameNum() % 10 == 0) { glm::vec3 location(ofRandom(this->fbo.getWidth()), ofRandom(this->fbo.getHeight()), ofRandom(800, 1500)); unique_ptr<Ripple> ripple(new Ripple(location)); this->ripple_list.push_back(move(ripple)); } this->fbo.begin(); ofClear(0); for (int i = this->ripple_list.size() - 1; i >= 0; i--) { if (this->ripple_list[i]->isDead()) { this->ripple_list.erase(this->ripple_list.begin() + i); } else { this->ripple_list[i]->update(); this->ripple_list[i]->draw(this->font, this->word_list); } } this->fbo.end(); this->fbo.readToPixels(this->pixels); cv::Mat gray_mat; cv::cvtColor(this->pixels_mat, gray_mat, cv::COLOR_RGBA2GRAY); for (int y = 0; y < this->pixels_mat.cols; y++) { for (int x = 0; x < this->pixels_mat.rows; x++) { if (gray_mat.at<unsigned char>(y, x) > 0) { this->pixels_mat.at<cv::Vec4b>(y, x) = cv::Vec4b(gray_mat.at<unsigned char>(y, x), gray_mat.at<unsigned char>(y, x), gray_mat.at<unsigned char>(y, x), this->pixels_mat.at<cv::Vec4b>(y, x)[3]); } } } cv::GaussianBlur(this->pixels_mat, this->pixels_mat, cv::Size(19, 19), 10, 10); } //-------------------------------------------------------------- void ofApp::draw() { ofSetColor(255); ofImage draw_image; draw_image.setFromPixels(this->pixels); draw_image.draw(-5, -5); this->fbo.draw(-25, -25); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#pragma once #include "ofMain.h" class Ripple { public: Ripple(); Ripple(glm::vec3 location); void update(); void draw(ofTrueTypeFont& font, vector<string>& word_list); bool isDead(); private: glm::vec3 location; float radius; float radius_max; float radius_span; }; |
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 |
#include "Ripple.h" //-------------------------------------------------------------- Ripple::Ripple() : Ripple(glm::vec3()) { } //-------------------------------------------------------------- Ripple::Ripple(glm::vec3 location) { this->location = location; this->radius = 1; this->radius_max = location.z / 10; } //-------------------------------------------------------------- void Ripple::update() { if (this->location.z > 0) { this->location.z = this->location.z > 10 ? this->location.z - 10 : 0; return; } if (this->radius < this->radius_max) { this->radius += 1; } } //-------------------------------------------------------------- void Ripple::draw(ofTrueTypeFont& font, vector<string>& word_list) { ofPushMatrix(); ofTranslate(this->location); if (this->location.z > 0) { ofSetColor(39); ofDrawLine(glm::vec3(), glm::vec3(0, 0, 30)); } else { auto alpha = this->radius < this->radius_max * 0.5 ? 255 : ofMap(this->radius, this->radius_max * 0.5, this->radius_max, 255, 10); ofSetColor(39, alpha); for (int deg = 0; deg < 360; deg += 20) { glm::vec2 word_location(this->radius * cos(deg * DEG_TO_RAD), this->radius * sin(deg * DEG_TO_RAD)); auto noise_seed_location = glm::vec2(this->location) + word_location; int word_index = ofMap(ofNoise(glm::vec3(noise_seed_location * 0.003, ofGetFrameNum() * 0.001)), 0, 1, 0, word_list.size()); ofPushMatrix(); ofTranslate(word_location); ofRotateZ(deg + 90); font.drawString(word_list[word_index], -10.5, 10); ofPopMatrix(); } } ofPopMatrix(); } //-------------------------------------------------------------- bool Ripple::isDead() { return this->radius >= this->radius_max; } |