[ Video ]
[ About ]
33歳になりました。
[ 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 |
#pragma once #include "ofMain.h" #include "Confetti.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) {}; ofTrueTypeFont font; ofVec2f font_size_1, font_size_2; string message_1 = "Today is my birthday!!"; string message_2 = "11 / 03"; vector<shared_ptr<Confetti>> confetti; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(255); ofSetWindowTitle("Insta"); for (int i = 0; i < 2048; i++) { this->confetti.push_back(shared_ptr<Confetti>(new Confetti())); } this->font.loadFont("fonts/Kazesawa-Bold.ttf", 48); this->font_size_1.x = this->font.stringWidth(message_1); this->font_size_1.y = this->font.stringHeight(message_1); this->font_size_2.x = this->font.stringWidth(message_2); this->font_size_2.y = this->font.stringHeight(message_2); } //-------------------------------------------------------------- void ofApp::update() { for (int i = 0; i < this->confetti.size(); i++) { this->confetti[i]->update(); } } //-------------------------------------------------------------- void ofApp::draw() { ofSetColor(0, 128, 255); this->font.drawString(message_1, ofGetWidth() / 2 - this->font_size_1.x / 2, ofGetHeight() / 2 - this->font_size_1.y / 2); this->font.drawString(message_2, ofGetWidth() / 2 - this->font_size_2.x / 2, ofGetHeight() / 2 + this->font_size_2.y / 2); for (int i = 0; i < this->confetti.size(); i++) { this->confetti[i]->draw(); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(1920, 1080, OF_WINDOW); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#pragma once #include "ofMain.h" class Confetti { public: Confetti(); ~Confetti() {}; void update(); void draw(); private: ofVec3f location; ofVec3f velocity; ofVec3f rotate; ofColor body_color; }; |
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 |
#include "Confetti.h" Confetti::Confetti() { this->location = ofVec3f(ofRandom(ofGetWidth()), ofRandom(ofGetHeight(), ofRandom(-50, 50))); this->velocity = ofVec3f(ofRandom(-3, 3), ofRandom(0.5, 3), ofRandom(-0.5, 0.5)); this->rotate = ofVec3f(0, 0, 0); this->body_color.setHsb(ofRandom(255), 255, 255); } void Confetti::update() { this->location += this->velocity; if (this->location.x < 0) { this->location.x = ofGetWidth(); } if (this->location.x > ofGetWidth()) { this->location.x = 0; } if (this->location.y > ofGetHeight()) { this->location.y = -20; if (this->location.z < -50) { this->location.z = 50; } if (this->location.z > 50) { this->location.z = -50; } } this->rotate.x += this->velocity.x; this->rotate.y += this->velocity.y; this->rotate.z += this->velocity.z; } void Confetti::draw() { ofPushMatrix(); ofTranslate(this->location); ofRotateX(this->rotate.x); ofRotateY(this->rotate.y); ofRotateZ(this->rotate.z); ofSetColor(this->body_color); ofDrawRectangle(ofVec3f(), 15, 15); ofPopMatrix(); } |