[ Video ]
[ About ]
球体を文字で埋める。
Fill the sphere with letters.
[ 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 |
#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::vec3> location_list; vector<float> radius_list; vector<glm::vec3> base_location_list; vector<ofPath> chara_path; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofSetLineWidth(3); ofEnableDepthTest(); auto ico_sphere = ofIcoSpherePrimitive(1, 5); this->base_location_list = ico_sphere.getMesh().getVertices(); while (this->location_list.size() < 400) { int index = ofRandom(this->base_location_list.size()); auto tmp_location = this->base_location_list[index]; tmp_location = glm::normalize(tmp_location) * ofRandom(0, 95); auto radius = this->location_list.size() < 110 ? ofRandom(10, 50) : ofRandom(3, 20); bool flag = true; for (int i = 0; i < this->location_list.size(); i++) { if (glm::distance(tmp_location, location_list[i]) < this->radius_list[i] + radius) { flag = false; break; } } if (flag) { this->location_list.push_back(tmp_location); this->radius_list.push_back(radius); } } ofTrueTypeFont font; font.loadFont("fonts/Kazesawa-Bold.ttf", 100, true, true, true); for (char c = 'A'; c <= 'Z'; c++) { this->chara_path.push_back(font.getCharacterAsPoints(c, true, false)); } } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum()); for (int i = 0; i < this->location_list.size(); i++) { ofPushMatrix(); ofTranslate(this->location_list[i]); ofRotateZ(ofMap(ofNoise(ofRandom(100), ofGetFrameNum() * 0.005), 0, 1, -360, 360)); ofRotateY(ofMap(ofNoise(ofRandom(100), ofGetFrameNum() * 0.005), 0, 1, -360, 360)); ofRotateX(ofMap(ofNoise(ofRandom(100), ofGetFrameNum() * 0.005), 0, 1, -360, 360)); int chara_index = i % this->chara_path.size(); chara_index = (int)(chara_index + ofMap(ofNoise(glm::vec4(this->location_list[i] * 0.005, ofGetFrameNum() * 0.00015)), 0, 1, 0, chara_path.size())) % chara_path.size(); auto font_size = radius_list[i] * 1.5; auto outline = this->chara_path[chara_index].getOutline(); ofFill(); ofSetColor(255); ofBeginShape(); for (int line_index = 0; line_index < outline.size(); line_index++) { if (line_index != 0) { ofNextContour(true); } auto vertices = outline[line_index].getVertices(); for (int vertices_index = 0; vertices_index < vertices.size(); vertices_index++) { auto point = (vertices[vertices_index] / 100 * font_size) + glm::vec2(font_size * -0.5, font_size * 0.5); ofVertex(point); } } ofEndShape(true); ofNoFill(); ofSetColor(0); ofBeginShape(); for (int line_index = 0; line_index < outline.size(); line_index++) { if (line_index != 0) { ofNextContour(true); } auto vertices = outline[line_index].getVertices(); for (int vertices_index = 0; vertices_index < vertices.size(); vertices_index++) { auto point = (vertices[vertices_index] / 100 * font_size) + glm::vec2(font_size * -0.5, font_size * 0.5); ofVertex(point); } } ofEndShape(true); ofPopMatrix(); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |