[ Video ]
[ About ]
文字による文字
Charactor by charactor.
[ Source ]
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" #include "MyShapes.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) {}; vector<unique_ptr<My::Shape>> shapes; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(39); ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); ofTrueTypeFont font; font.loadFont("fonts/Kazesawa-Bold.ttf", 300, true, true, true); ofFbo fbo; fbo.allocate(ofGetWidth(), ofGetHeight()); fbo.begin(); ofSetColor(0); string word_1 = "AB"; font.drawString(word_1, ofGetWidth() * 0.5 - font.stringWidth(word_1) * 0.5, ofGetHeight() * 0.48); string word_2 = "CD"; font.drawString(word_2, ofGetWidth() * 0.5 - font.stringWidth(word_2) * 0.5, ofGetHeight() * 0.52 + font.stringHeight(word_1)); fbo.end(); vector<ofPath> path_list; path_list.push_back(font.getCharacterAsPoints('A', true, false)); path_list.push_back(font.getCharacterAsPoints('B', true, false)); path_list.push_back(font.getCharacterAsPoints('C', true, false)); path_list.push_back(font.getCharacterAsPoints('D', true, false)); ofPixels pix; fbo.readToPixels(pix); while (this->shapes.size() < 350) { int x = ofRandom(ofGetWidth()); int y = ofRandom(ofGetHeight()); ofColor pix_color = pix.getColor(x, y); if (pix_color != ofColor(0)) { continue; } auto location = glm::vec2(x, y); float radius = ofRandom(5, 20); auto flag = true; for (auto& shape : this->shapes) { if (glm::distance(location, shape->location) < radius + shape->radius) { flag = false; break; } } if (flag) { unique_ptr<My::Shape> shape; int r = ofRandom(path_list.size()); shape = make_unique<My::Path>(location, radius, path_list[r]); this->shapes.push_back(move(shape)); } } } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { for (auto& shape : this->shapes) { shape->draw(); } } //-------------------------------------------------------------- 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#pragma once #include "ofMain.h" namespace My { class Shape { public: Shape(glm::vec2 location, float radius); ~Shape() {}; virtual void draw() = 0; glm::vec2 location; float radius; bool fill; }; class Circle : public Shape { public: Circle(glm::vec2 location, float radius); void draw() override; private: int deg; }; class Rectangle : public Shape { public: Rectangle(glm::vec2 location, float radius); void draw() override; private: float len; float speed; int direction; }; class Path : public Shape { public: Path(glm::vec2 location, float radius, ofPath path); void draw() override; ofPath path; private: int rotate; }; } |
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 |
#include "MyShapes.h" // Shape //-------------------------------------------------------------- My::Shape::Shape(glm::vec2 location, float radius) { this->location = location; this->radius = radius; this->fill = ofRandom(1) < 0.5 ? true : false; } // Circle //-------------------------------------------------------------- My::Circle::Circle(glm::vec2 location, float radius) : Shape(location, radius) { this->deg = ofRandom(360); } //-------------------------------------------------------------- void My::Circle::draw() { ofPushMatrix(); ofTranslate(this->location); ofRotate(this->deg); this->fill ? ofFill() : ofNoFill(); ofSetColor(39); ofDrawCircle(glm::vec2(), this->radius); float tmp_radius = ofNoise(this->location.x * 0.005, this->location.y * 0.005, ofGetFrameNum() * 0.005) * this->radius; this->fill ? ofSetColor(239) : ofFill(); ofBeginShape(); for (int deg = 0; deg < 360; deg += 36) { if (deg % 72 == 0) { ofVertex(tmp_radius * cos(deg * DEG_TO_RAD), tmp_radius * sin(deg * DEG_TO_RAD)); } else { ofVertex(tmp_radius * 0.5 * cos(deg * DEG_TO_RAD), tmp_radius * 0.5 * sin(deg * DEG_TO_RAD)); } } ofEndShape(true); ofPopMatrix(); } // Rectangle //-------------------------------------------------------------- My::Rectangle::Rectangle(glm::vec2 location, float radius) : Shape(location, radius) { this->len = radius * sqrt(2); this->speed = ofRandom(0.5, 3); this->direction = ofRandom(1) < 0.5 ? -1 : 1; } //-------------------------------------------------------------- void My::Rectangle::draw() { ofPushMatrix(); ofTranslate(this->location); ofRotate(ofGetFrameNum() * this->speed * this->direction); this->fill ? ofFill() : ofNoFill(); ofSetColor(39); ofDrawRectangle(glm::vec2(), this->len, this->len); ofPopMatrix(); } // Path //-------------------------------------------------------------- My::Path::Path(glm::vec2 location, float radius, ofPath path) : Shape(location, radius) { this->path = path; this->rotate = ofRandom(360); } //-------------------------------------------------------------- void My::Path::draw() { this->fill ? ofFill() : ofNoFill(); auto tmp_radius = this->radius * 1.5; ofPushMatrix(); ofTranslate(this->location); ofRotate(this->rotate++); auto outline = path.getOutline(); 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 i = 0; i < vertices.size(); i++) { ofVertex((vertices[i] / 300 * tmp_radius) + glm::vec2(tmp_radius * -0.5, tmp_radius * 0.5)); } } ofEndShape(true); ofPopMatrix(); } |