[ Video ]
[ About ]
ofFboに文字(CODE LIFE)を描写、色・座標情報にアクセスできるようにofPixelsへコピーします。
画面内に収まる座標(x, y)をランダムに生成、ofPixelsの色情報を調べて、文字と重なる座標かどうかを調べて行きます。
文字と重なる座標を一定数集めたら、Noise関数で動きをつけて点を描写。更にそれぞれの点同士の座標が一定距離以内に収まればお互いを結ぶ線を生成します。
[ 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 |
#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 windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; float font_size; ofTrueTypeFont font; ofFbo fbo; ofPixels pix; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(39); ofSetWindowTitle("Insta"); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 250, true, true, true); this->fbo.allocate(ofGetWidth(), ofGetHeight()); this->fbo.begin(); ofClear(0); ofSetColor(0); ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); string word_1 = "CODE"; string word_2 = "LIFE"; this->font.drawString(word_1, this->font.stringWidth(word_1) * -0.5, this->font.stringHeight(word_1) * -0.3); this->font.drawString(word_2, this->font.stringWidth(word_2) * -0.5, this->font.stringHeight(word_2) * 1.3); this->fbo.end(); this->fbo.readToPixels(this->pix); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { int number_of_circle = 600; vector<ofPoint> points; while (points.size() < number_of_circle) { int x = ofRandom(ofGetWidth()); int y = ofRandom(ofGetHeight()); ofColor pix_color = this->pix.getColor(x, y); if (pix_color != ofColor(0)) { continue; } float x_increase = ofMap(ofNoise(ofRandom(number_of_circle), ofGetFrameNum() * 0.005), 0, 1, -20, 20); float y_increase = ofMap(ofNoise(ofRandom(number_of_circle), ofGetFrameNum() * 0.005), 0, 1, -20, 20); x += x_increase; y += y_increase; points.push_back(ofPoint(x, y)); } for (int i = 0; i < points.size(); i++) { ofColor color; color.setHsb(ofRandom(255), 255, 255); ofSetColor(color); ofDrawCircle(points[i], 3); for(int j = 0; j < points.size(); j++){ float distance = points[i].distance(points[j]); if (distance < 50) { ofSetColor(color, ofMap(distance, 0, 50, 255, 0)); ofDrawLine(points[i], points[j]); } } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(1280, 720, OF_WINDOW); ofRunApp(new ofApp()); } |