[ Video ]
[ About ]
トーラスの座標上を走るParticleを作成、お互いの距離を見て線を描写しています。
[ 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 |
#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; std::vector<std::unique_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 41 42 43 44 45 46 47 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(255); ofSetWindowTitle("Insta"); ofEnableDepthTest(); ofSetLineWidth(1.2); for (int i = 0; i < 512; i++) { std::unique_ptr<Particle> particle(new Particle(i * 0.5)); this->particles.push_back(std::move(particle)); } } //-------------------------------------------------------------- void ofApp::update() { for (int i = 0; i < this->particles.size(); i++) { this->particles[i]->update(); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); 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 19 20 21 22 23 24 25 26 |
#pragma once #include "ofMain.h" class Particle { public: Particle(float value); ~Particle(); void update(); void draw(const vector<unique_ptr<Particle>> &particles); ofPoint make_point(float radius, float small_radius, float deg, float small_deg); ofPoint get_location(); private: float radius; float small_radius; float deg; float small_deg; float deg_span; float small_deg_span; ofColor body_color; ofPoint location; }; |
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 |
#include "Particle.h" //-------------------------------------------------------------- Particle::Particle(float value) { this->radius = 230; this->small_radius = 50; this->deg = ofRandom(0, 360); this->small_deg = ofRandom(0, 360); this->deg_span = ofRandom(0.25, 1.5); this->small_deg_span = ofRandom(5, 10); this->body_color = ofColor(0); this->location = this->make_point(this->radius, this->small_radius, this->deg, this->small_deg); } //-------------------------------------------------------------- Particle::~Particle() { } //-------------------------------------------------------------- void Particle::update() { this->deg += this->deg_span; this->small_deg += this->small_deg_span; this->location = this->make_point(this->radius, this->small_radius, this->deg, this->small_deg); } //-------------------------------------------------------------- void Particle::draw(const vector<unique_ptr<Particle>> &particles) { ofSetColor(this->body_color); ofDrawSphere(this->location, 1.5); for (int i = 0; i < particles.size(); i++) { float distance = this->location.distance(particles[i]->get_location()); if (distance < 50) { ofSetColor(this->body_color, ofMap(distance, 0, 50, 255, 0)); ofDrawLine(this->location, particles[i]->get_location()); } } } //-------------------------------------------------------------- ofPoint Particle::make_point(float radius, float small_radius, float deg, float small_deg) { float x_1 = radius * cos(deg * DEG_TO_RAD); float y_1 = radius * sin(deg * DEG_TO_RAD); float x_2 = small_radius * cos(small_deg * DEG_TO_RAD) * cos(deg * DEG_TO_RAD); float y_2 = small_radius * cos(small_deg * DEG_TO_RAD) * sin(deg * DEG_TO_RAD); float x = x_1 + x_2; float y = y_1 + y_2; float z = small_radius * sin(small_deg * DEG_TO_RAD); return ofPoint(x, y, z); } //-------------------------------------------------------------- ofPoint Particle::get_location(){ return this->location; } |