[ Video ]
[ About ]
Particleが文字の輪郭が近づくとLineが引かれます。普段はParticle同士で線を引いていますが、別のオブジェクトの関係に変えてみました。
それぞれのSNSにアップロードしたときにエンコードが加わって絵がつぶれてしまうかも(つぶれてますね)知れませんが綺麗です。特別なaddonが無くてもopenFrameworksのみで動きますので、動かす環境がある方は是非、実機でご確認下さい。
OpenCVでエッジを抽出して、エッジ × 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 26 27 28 29 30 31 32 33 |
#pragma once #include "ofMain.h" #include "ofFbo.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; ofFbo fbo; ofTrueTypeFont font; string words; ofPoint words_size; vector<ofTTFCharacter> paths; 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); ofSetLineWidth(1.3); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 250, true, false, true); this->words = "YES"; this->words_size = ofPoint(this->font.stringWidth(this->words), this->font.stringHeight(this->words)); this->paths = this->font.getStringAsPoints(this->words); for (int i = 0; i < 512; i++) { unique_ptr<Particle> particle(new Particle()); this->particles.push_back(std::move(particle)); } this->fbo.allocate(ofGetWidth(), ofGetHeight()); } //-------------------------------------------------------------- void ofApp::update() { this->fbo.begin(); ofClear(0); for (int i = 0; i < this->particles.size(); i++) { this->particles[i]->update(); } for (int p_index = 0; p_index < this->paths.size(); p_index++) { vector<ofPolyline> outline = this->paths[p_index].getOutline(); for (int o_index = 0; o_index < outline.size(); o_index++) { outline[o_index] = outline[o_index].getResampledBySpacing(15); vector<ofPoint> vertices = outline[o_index].getVertices(); for (int v_index = 0; v_index < vertices.size(); v_index++) { ofPoint point = vertices[v_index] + ofPoint(ofGetWidth() / 2, ofGetHeight() / 2) - ofPoint(this->words_size.x / 2, -this->words_size.y / 2); for (int i = 0; i < this->particles.size(); i++) { float distance = this->particles[i]->get_location().distance(point); if (distance < 80) { ofSetColor(this->particles[i]->get_body_color(), ofMap(distance, 0, 80, 255, 0)); ofDrawLine(point, this->particles[i]->get_location()); } } } } } this->fbo.end(); } //-------------------------------------------------------------- void ofApp::draw() { this->fbo.draw(0, 0); } //======================================================================== 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 |
#pragma once #include "ofMain.h" class Particle { public: Particle(); ~Particle() {}; void apply_force(ofVec2f force); void update(); void draw(); void set_color(ofColor body_color); ofVec2f get_location(); ofColor get_body_color(); private: ofVec2f location; ofVec2f velocity; ofVec2f acceleration; 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 57 58 59 60 61 62 63 64 65 |
#include "Particle.h" Particle::Particle() { this->location = ofVec2f(ofRandom(ofGetWidth()), ofRandom(ofGetHeight())); this->velocity = ofVec2f(ofRandom(-3, 3), ofRandom(-3, 3)); this->velocity = this->velocity.normalized() * ofRandom(1, 3); this->acceleration = ofVec2f(); this->body_color.setHsb(ofRandom(255), 255, 255); } void Particle::apply_force(ofVec2f force) { this->acceleration += force; } void Particle::update() { this->acceleration += this->velocity; this->location += this->acceleration; this->acceleration *= 0; if (this->location.x < 0) { this->location.x = 0; this->velocity.x *= -1; } else if (this->location.x > ofGetWidth()) { this->location.x = ofGetWidth(); this->velocity.x *= -1; } if (this->location.y < 0) { this->location.y = 0; this->velocity.y *= -1; } else if (this->location.y > ofGetHeight()) { this->location.y = ofGetHeight(); this->velocity.y *= -1; } } void Particle::draw() { ofSetColor(this->body_color); ofDrawCircle(this->location, 3); } void Particle::set_color(ofColor body_color) { this->body_color = body_color; } ofVec2f Particle::get_location() { return this->location; } ofColor Particle::get_body_color() { return this->body_color; } |