[ Video ]
[ About ]
今日は会社の飲み会なので絵文字(Emoji)を使ってお酒を並べてみました。ofTrueTypeFontのdrawStringだと色合成されなかったのでofFboを3枚重ねました。
[ 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 |
#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) {}; vector<ofFbo> fbos; ofTrueTypeFont font; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(39); ofSetWindowTitle("Insta"); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); ofTrueTypeFontSettings font_settings("fonts/EmojiSymbols-Regular.ttf", 30); font_settings.antialiased = true; font_settings.addRanges(ofAlphabet::Emoji); this->font.load(font_settings); for (int i = 0; i < 3; i++) { ofFbo fbo; fbo.allocate(ofGetWidth(), ofGetHeight()); this->fbos.push_back(fbo); } } //-------------------------------------------------------------- void ofApp::update() { vector<string> emojis = { u8"🍶" , u8"🍷" , u8"🍸" , u8"🍹" , u8"🍺", u8"🍻" }; vector<ofColor> colors{ ofColor(255, 0, 0), ofColor(0, 255, 0), ofColor(0, 0, 255) }; for (int i = 0; i < 3; i++) { ofSeedRandom(39); this->fbos[i].begin(); ofClear(0); ofSetColor(colors[i]); for (int x = 50; x < ofGetWidth(); x += 100) { for (int y = 75; y < ofGetHeight(); y += 100) { int emoji_index = ofRandom(emojis.size()); ofPoint point(x + ofMap(ofNoise(i + ofRandom(100) + ofGetFrameNum() * 0.005), 0, 1, -30, 30), y + ofMap(ofNoise(i + ofRandom(100) + ofGetFrameNum() * 0.005), 0, 1, -30, 30)); this->font.drawString(emojis[emoji_index], point.x, point.y); } } this->fbos[i].end(); } } //-------------------------------------------------------------- void ofApp::draw() { for (int i = 0; i < 3; i++) { this->fbos[i].draw(0, 0); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |