[ Video ]
[ About ]
あけましておめでとうございます。
A HAPPY NEW YEAR!!
[ 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 34 |
#pragma once #include "ofMain.h" #include "ofFbo.h" #include "Particle.h" class ofApp : public ofBaseApp { public: ~ofApp(); 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) {}; ofFbo fbo; ofTrueTypeFont font; vector<string> words; vector<ofTTFCharacter> font_paths; vector<Particle*> particles; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- //-------------------------------------------------------------- ofApp::~ofApp() { for (int i = this->particles.size() - 1; i > -1; i--) { delete this->particles[i]; this->particles.erase(this->particles.begin() + i); } } //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 120, true, false, true); this->words.push_back("HAPPY"); this->words.push_back("NEW"); this->words.push_back("YEAR"); this->fbo.allocate(ofGetWidth(), ofGetHeight()); } //-------------------------------------------------------------- void ofApp::update() { for (int i = this->particles.size() - 1; i > -1; i--) { this->particles[i]->update(); if (this->particles[i]->isDead()) { delete this->particles[i]; this->particles.erase(this->particles.begin() + i); } } this->fbo.begin(); ofClear(0); ofTranslate(10, 200); float distance; for (int i = 0; i < this->particles.size(); i++) { for (int j = i; j < this->particles.size(); j++) { distance = this->particles[i]->get_location().distanceSquared(this->particles[j]->get_location()); if (distance < 100) { ofSetColor(this->particles[i]->get_body_color(), this->particles[i]->get_alpha()); ofDrawLine(this->particles[i]->get_location(), this->particles[j]->get_location()); } } } this->fbo.end(); } //-------------------------------------------------------------- void ofApp::draw() { this->fbo.draw(0, 0); } //-------------------------------------------------------------- void ofApp::keyPressed(int key) { for (int word_index = 0; word_index < this->words.size(); word_index++) { this->font_paths = this->font.getStringAsPoints(this->words[word_index]); for (int moji_index = 0; moji_index < this->words[word_index].size(); moji_index++) { for (int polyline_index = 0; polyline_index < (int)this->font_paths[moji_index].getOutline().size(); polyline_index++) { ofPolyline polyline = this->font_paths[moji_index].getOutline()[polyline_index].getResampledBySpacing(5); if (polyline_index != 0)ofNextContour(true); vector<ofPoint> points = polyline.getVertices(); for (int point_index = 0; point_index < (int)points.size(); point_index++) { ofColor color; color.setHsb(ofRandom(255), 255, 255); ofVec3f location = ofVec3f(points[point_index].x + (150 * word_index), points[point_index].y + (200 * word_index)); this->particles.push_back(new Particle(location, ofVec2f(ofRandom(-0.5, 0.5), ofRandom(-0.5, 0.5)), color)); } } } } } //-------------------------------------------------------------- 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 20 21 22 23 24 |
#pragma once #include "ofMain.h" class Particle { public: Particle(); Particle(ofVec2f location, ofVec2f velocity, ofColor body_color); ~Particle(); void update(); void draw(); ofVec2f get_location(); ofColor get_body_color(); float get_alpha(); bool isDead(); private: ofVec2f location; ofVec2f velocity; float body_size; ofColor body_color; int alpha; }; |
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 |
#include "Particle.h" Particle::Particle() : Particle(ofVec2f(0, 0), ofVec2f(0, 0), ofColor(128)) { } Particle::Particle(ofVec2f location, ofVec2f velocity, ofColor body_color) { this->location = location; this->velocity = velocity; this->alpha = 255; this->body_size = velocity.length() / 2; this->body_color = body_color; } Particle::~Particle() { } void Particle::update() { this->location += this->velocity; this->alpha -= 3; } void Particle::draw() { } ofVec2f Particle::get_location() { return this->location; } ofColor Particle::get_body_color() { return this->body_color; } float Particle::get_alpha() { return this->alpha; } bool Particle::isDead() { return this->alpha < 0; } |