[ Video ]
[ About ]
トリック・オア・トリート🎃🍭👻!
Trick or Treat🎃🍭👻.
[ 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 |
#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 windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofTrueTypeFont font; vector<ofPoint> locations; vector<ofColor> colors; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(39); int font_size = 170; this->font.loadFont("fonts/Kazesawa-Bold.ttf", font_size, true, true, true); ofFbo fbo; fbo.allocate(ofGetWidth(), ofGetHeight()); fbo.begin(); ofClear(0); string word = "TRICK"; font.drawString(word, 0, font_size + 50); word = "OR"; font.drawString(word, ofGetWidth() * 0.5 - font.stringWidth(word) * 0.5, ofGetHeight() * 0.5 + font_size * 0.5); word = "TREAT"; font.drawString(word, ofGetWidth() - font.stringWidth(word), ofGetHeight() - 55); fbo.end(); ofPixels pixels; fbo.readToPixels(pixels); font_size = 20; for (int x = 0; x < fbo.getWidth(); x += font_size) { for (int y = 0; y < fbo.getHeight(); y += font_size) { if (pixels.getColor(x, y) != ofColor(0, 0)) { this->locations.push_back(ofPoint(x, y)); ofColor color; color.setHsb(ofRandom(255), 255, 255); this->colors.push_back(color); } } } ofTrueTypeFontSettings font_settings("fonts/EmojiSymbols-Regular.ttf", font_size); font_settings.antialiased = true; font_settings.addRanges(ofAlphabet::Emoji); this->font.load(font_settings); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { vector<string> words = { u8"🎃", u8"🍭", u8"👻", }; for (int i = 0; i < this->locations.size(); i++) { ofPoint point = this->locations[i]; int words_index = ofNoise(point.x * 0.003, point.y * 0.003, ofGetFrameNum() * 0.005) * words.size(); std::string moji = words[words_index]; if (words_index == 0) { ofSetColor(229, 163, 35); } else if(words_index == 1) { ofSetColor(this->colors[i]); } else { ofSetColor(239); } this->font.drawString(moji, point.x, point.y); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |