[ Video ]
[ About ]
トーラス座標上に伸びた線が伸びたり縮んだりします。
[ 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofEnableDepthTest(); ofSetLineWidth(1.2); ofColor body_color; for (int i = 0; i < 12; i++) { switch (i) { case 0: body_color = ofColor(255, 0, 0); break; case 4: body_color = ofColor(0, 255, 0); break; case 8: body_color = ofColor(0, 0, 255); break; default: body_color = ofColor(255); break; } std::unique_ptr<Particle> particle(new Particle(i * 30, body_color)); 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 |
#pragma once #include "ofMain.h" class Particle { public: Particle(float value, ofColor body_color); ~Particle(); void update(); void draw(const vector<unique_ptr<Particle>> &particles); ofPoint make_point(float radius, float small_radius, float deg, float small_deg); private: float radius; float small_radius; float deg; float small_deg; float deg_span; float small_deg_span; float value; 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 |
#include "Particle.h" //-------------------------------------------------------------- Particle::Particle(float value, ofColor body_color) { this->radius = 230; this->small_radius = 50; this->deg = 0; this->small_deg = value; this->deg_span = 2; this->small_deg_span = 10; this->value = value; this->body_color = body_color; } //-------------------------------------------------------------- Particle::~Particle() { } //-------------------------------------------------------------- void Particle::update() { } //-------------------------------------------------------------- void Particle::draw(const vector<unique_ptr<Particle>> &particles) { ofSetColor(this->body_color); int max = ofNoise(this->value * 0.05, ofGetFrameNum() * 0.005) * (360.f / this->deg_span); for (int i = 0; i < max; i++) { ofVec3f point_1 = make_point(this->radius, this->small_radius, this->deg - this->deg_span * i, this->small_deg - this->small_deg_span * i); ofVec3f point_2 = make_point(this->radius, this->small_radius, this->deg - this->deg_span * (i + 1), this->small_deg - this->small_deg_span * (i + 1)); ofDrawLine(point_1, point_2); } ofVec3f point = make_point(this->radius, this->small_radius, this->deg - this->deg_span * max, this->small_deg - this->small_deg_span * max); ofDrawSphere(point, 3); } //-------------------------------------------------------------- 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); } |