[ Video ]
[ About ]
A to Z.
[ 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 34 |
#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) {}; void create_particles(char moji_1, char moji_2); char moji_1; char moji_2; float progress; ofTrueTypeFont font; vector<Particle> particles; int particle_count; }; |
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->particle_count = 600; this->font.loadFont("Kazesawa-Bold.ttf", 450, true, false, true); this->moji_1 = '?'; this->moji_2 = '@'; this->progress = 0; this->create_particles(this->moji_1, this->moji_2); } //-------------------------------------------------------------- void ofApp::update() { this->progress += 0.05; if (this->progress > 2) { this->progress = 0; this->moji_1 = this->moji_2; this->moji_2 = this->moji_1 + 1; this->create_particles(this->moji_1, this->moji_2); } for (int i = 0; i < this->particle_count; i++) { this->particles[i].set_progress(this->progress); this->particles[i].update(); } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() / 2 - this->font.stringWidth("W") / 2, ofGetHeight() / 2 + this->font.stringHeight("W") / 2); for (int i = 0; i < this->particle_count; i++) { this->particles[i].draw(); } } //-------------------------------------------------------------- void ofApp::create_particles(char moji_1, char moji_2) { this->particles.clear(); this->particles.shrink_to_fit(); for (int i = 0; i < this->particle_count; i++) { this->particles.push_back(Particle()); } ofTTFCharacter char_1_path = this->font.getCharacterAsPoints(moji_1); ofTTFCharacter char_2_path = this->font.getCharacterAsPoints(moji_2); vector<ofPolyline> outline_1 = char_1_path.getOutline(); vector<ofPolyline> outline_2 = char_2_path.getOutline(); int count_1 = this->particle_count / outline_1.size(); int count_2 = this->particle_count / outline_2.size(); int particle_index = 0; for (int outline_index = 0; outline_index < outline_1.size(); outline_index++) { outline_1[outline_index] = outline_1[outline_index].getResampledByCount(count_1); vector<ofPoint> vertices = outline_1[outline_index].getVertices(); for (int vertices_index = 0; vertices_index < vertices.size(); vertices_index++) { this->particles[particle_index].set_point_1(vertices[vertices_index]); particle_index++; } } //particle_index = 0; for (int outline_index = 0; outline_index < outline_2.size(); outline_index++) { outline_2[outline_index] = outline_2[outline_index].getResampledByCount(count_2); vector<ofPoint> vertices = outline_2[outline_index].getVertices(); for (int vertices_index = 0; vertices_index < vertices.size(); vertices_index++) { this->particles[particle_index].set_point_2(vertices[vertices_index]); particle_index--; } } } //-------------------------------------------------------------- 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(); Particle(ofVec3f point_1, ofVec3f point_2); void update(); void draw(); void set_point_1(ofVec3f point_1); void set_point_2(ofVec3f point_2); void set_progress(float value); ofVec3f get_location(); private: ofVec3f location; ofVec3f point_1; ofVec3f point_2; float progress; ofImage img; }; |
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 |
#include "Particle.h" Particle::Particle() : Particle(ofVec3f(0, 0, 0), ofVec3f(0, 0, 0)) {} Particle::Particle(ofVec3f point_1, ofVec3f point_2) { this->point_1 = point_1; this->point_2 = point_2; this->location = this->point_1; this->progress = 0.f; int size = 200; int r = 55; int g = 100; int b = 180; this->img.allocate(size, size, OF_IMAGE_COLOR); unsigned char* pixels = this->img.getPixels().getData(); for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { float distance = ((size / 2 - x) * (size / 2 - x) + (size / 2 - y) * (size / 2 - y)) / 50.f; if (distance == 0) { distance = 0.003; } int r_value = r / distance - 3; r_value = max(0, min(r_value, 255)); int g_value = g / distance - 3; g_value = max(0, min(g_value, 255)); int b_value = b / distance - 3; b_value = max(0, min(b_value, 255)); pixels[x * 3 * size + y * 3 + 0] = r_value; pixels[x * 3 * size + y * 3 + 1] = g_value; pixels[x * 3 * size + y * 3 + 2] = b_value; } } this->img.update(); } void Particle::update(){ if (this->progress > 1) { this->progress = 1; } ofVec3f gap = this->point_2 - this->point_1; gap = gap * this->progress; this->location = this->point_1 + gap; } void Particle::draw() { if (this->point_1 != ofVec3f(0, 0, 0) || this->point_2 != ofVec3f(0, 0, 0)) { this->img.draw(this->location - ofVec3f(100, 100)); } } void Particle::set_point_1(ofVec3f point_1) { this->point_1 = point_1; } void Particle::set_point_2(ofVec3f point_2) { this->point_2 = point_2; } void Particle::set_progress(float value) { this->progress = value; } ofVec3f Particle::get_location() { return this->location; } |