[ 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 26 27 28 29 30 31 |
#pragma once #include "ofMain.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; vector<glm::vec2> location_list; vector<ofColor> color_list; vector<int> index_list; ofTrueTypeFont font; string word; }; |
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(255); ofSetLineWidth(2); //ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 15, true, true, true); this->word = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; vector<glm::vec2> location_list; ofColor color; for (int x = -400 - 15; x <= 400 - 15; x += 15) { for (int y = -400 + 15; y <= 400 + 15; y += 20) { this->location_list.push_back(glm::vec2(x + 10, y - 10)); color.setHsb(ofRandom(255), 255, 255); this->color_list.push_back(color); this->index_list.push_back(ofRandom(this->word.size())); } } } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(120); auto noise_location = glm::vec3(ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.01), 0, 1, -200, 200), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.01), 0, 1, -200, 200), 30); ofSetColor(0); ofDrawSphere(noise_location - glm::vec3(0, 0, 30), 10); ofColor color; for (int i = 0; i < this->location_list.size(); i++) { auto distance = glm::distance(noise_location, glm::vec3(this->location_list[i], 0)); auto deg = glm::vec3(); auto noise_seed = glm::vec3(ofRandom(1000), ofRandom(1000), ofRandom(1000)); if (distance < 150) { auto gap = glm::vec3(this->location_list[i], 0) - noise_location; auto location = noise_location + glm::normalize(gap) * 150; deg.x = ofMap(ofNoise(noise_seed.x, ofGetFrameNum() * 0.02), 0, 1, -180, 180); deg.y = ofMap(ofNoise(noise_seed.y, ofGetFrameNum() * 0.02), 0, 1, -180, 180); deg.z = ofMap(ofNoise(noise_seed.z, ofGetFrameNum() * 0.02), 0, 1, -180, 180); ofPushMatrix(); ofTranslate(location); ofRotateZ(deg.z); ofRotateY(deg.y); ofRotateX(deg.x); this->index_list[i] = (this->index_list[i] + 1) % this->word.size(); } else { ofPushMatrix(); ofTranslate(this->location_list[i]); ofRotateZ(deg.z); ofRotateY(deg.y); ofRotateX(deg.x); } ofPath chara_path = this->font.getCharacterAsPoints(this->word[this->index_list[i]], true, false); vector<ofPolyline> outline = chara_path.getOutline(); ofFill(); ofSetColor(this->color_list[i], 128); ofBeginShape(); for (int outline_index = 0; outline_index < outline.size(); outline_index++) { ofNextContour(true); auto vertices = outline[outline_index].getVertices(); for (auto& vertex : vertices) { ofVertex(vertex + glm::vec2(-6, 8)); } } ofEndShape(true); ofNoFill(); ofSetColor(this->color_list[i]); ofBeginShape(); for (int outline_index = 0; outline_index < outline.size(); outline_index++) { ofNextContour(true); auto vertices = outline[outline_index].getVertices(); for (auto& vertex : vertices) { ofVertex(vertex + glm::vec2(-6, 8)); } } ofEndShape(true); ofPopMatrix(); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |