[ Video ]
[ About ]
紙吹雪。
Confetti.
[ 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 |
#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) {}; ofEasyCam cam; 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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofEnableDepthTest(); for (int i = 0; i < 1024; i++) { this->confetti.push_back(shared_ptr<Confetti>(new Confetti())); } } //-------------------------------------------------------------- void ofApp::update() { for (int i = 0; i < this->confetti.size(); i++) { this->confetti[i]->update(); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofTranslate(0, 0, -ofGetWidth() / 2); ofRotateZ(180); ofTranslate(-ofGetWidth() / 2, -ofGetHeight() / 2); for (int i = 0; i < this->confetti.size(); i++) { this->confetti[i]->draw(); } this->cam.end(); } //-------------------------------------------------------------- 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 |
#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 50 |
#include "Confetti.h" Confetti::Confetti() { this->location = ofVec3f(ofRandom(ofGetWidth()), ofRandom(ofGetHeight(), ofRandom(ofGetWidth()))); this->velocity = ofVec3f(ofRandom(-3, 3), ofRandom(0.5, 3), ofRandom(-3, 3)); 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.z < 0) { this->location.z = ofGetWidth();; } if (this->location.z > ofGetWidth()) { this->location.z = 0; } if (this->location.y > ofGetHeight()) { this->location.y = 0; } 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(); } |