[ Video ]
[ About ]
3次元版.
3D Ver.
[ 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 "Particle.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<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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofBackground(0); ofSetWindowTitle("Insta"); ofEnableDepthTest(); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); for (int i = 0; i < 512; i++) { this->particles.push_back(shared_ptr<Particle>(new Particle())); } } //-------------------------------------------------------------- void ofApp::update() { for (int i = 0; i < this->particles.size(); i++) { this->particles[i]->update(); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum() * 0.5); for (int i = 0; i < this->particles.size(); i++) { this->particles[i]->draw(this->particles); } 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 18 |
#pragma once #include "ofMain.h" class Particle { public: Particle(); ~Particle() {}; void update(); void draw(vector<shared_ptr<Particle>> particles); ofVec3f get_location(); private: ofVec3f location; ofVec3f velocity; 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 51 52 53 54 55 56 |
#include "Particle.h" Particle::Particle() { this->location = ofVec3f(ofRandom(-ofGetWidth() / 2, ofGetWidth() / 2), ofRandom(-ofGetHeight() / 2, ofGetHeight() / 2), ofRandom(-ofGetWidth() / 2, ofGetWidth() / 2)); this->velocity = ofVec3f(ofRandom(-2, 2), ofRandom(-2, 2), ofRandom(-2, 2)); this->body_color.setHsb(ofRandom(255), 255, 255); //this->body_color = ofColor(0); } void Particle::update() { this->location += this->velocity; if (this->location.x < -ofGetWidth() / 2) { this->location.x = -ofGetWidth() / 2; this->velocity.x *= -1; } else if (this->location.x > ofGetWidth() / 2) { this->location.x = ofGetWidth() / 2; this->velocity.x *= -1; } if (this->location.y < -ofGetHeight() / 2) { this->location.y = -ofGetHeight() / 2; this->velocity.y *= -1; } else if (this->location.y > ofGetHeight() / 2) { this->location.y = ofGetHeight() / 2; this->velocity.y *= -1; } if (this->location.z < -ofGetWidth() / 2) { this->location.z = -ofGetWidth() / 2; this->velocity.z *= -1; } else if (this->location.z > ofGetWidth() / 2) { this->location.z = ofGetWidth() / 2; this->velocity.z *= -1; } } void Particle::draw(vector<shared_ptr<Particle>> particles) { ofSetColor(this->body_color); ofDrawSphere(this->location, 3); float distance; for (int i = 0; i < particles.size(); i++) { distance = this->location.distance(particles[i]->get_location()); if (distance > 0 && distance < 64) { ofDrawLine(this->location, particles[i]->get_location()); } } } ofVec3f Particle::get_location() { return this->location; } |