[ Video ]
[ About ]
Instagaramの投稿で、線で輪郭を表現している方がおりインスパイアされました。中心座標からの距離が一定以下の座標は、強制的に半径距離となる座標をとるように書き換えているので、中心から逃げているような動きになります。
[ 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 |
#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 windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofEasyCam cam; vector<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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofBackground(239); ofSetWindowTitle("Insta"); ofEnableDepthTest(); ofSetLineWidth(3); for (int i = 0; i < 1024; i++) { unique_ptr<Particle> particle(new Particle(500)); 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(); ofRotateX(180); for (int i = 0; i < this->particles.size(); i++) { this->particles[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 Particle { public: Particle(int len); void update(); void draw(); private: ofPoint location; ofPoint log; vector<ofPoint> logs; int len; float radius; }; |
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 "Particle.h" Particle::Particle(int len) { this->len = len; this->location = ofPoint(ofRandom(-this->len / 2, this->len / 2), ofRandom(-this->len, this->len), ofRandom(-this->len / 2, this->len / 2)); this->radius = this->len / 2; } void Particle::update() { ofPoint log = ofPoint(this->location.x, (int)(this->location.y + ofGetFrameNum() * 3) % (len * 2) - len, this->location.z); if (log.length() < this->radius) { log = log.normalize() * this->radius; } if (log.y <= -len + 3) { this->logs.clear(); } if (this->logs.size() > 24) { this->logs.erase(this->logs.begin()); } this->logs.push_back(log); } void Particle::draw() { if (this->logs.size() > 2) { for (int i = 1; i < this->logs.size(); i++) { ofSetColor(39, 10 * i - ofMap(this->logs[i].z, -this->len / 2, this->len / 2, 0, 255)); ofDrawLine(this->logs[i - 1], this->logs[i]); } } } |