[ Video ]
[ About ]
ofFboに描写した内容を、反転+透過+歪みなどを加えることで影のようにならないかと思い、試行錯誤してみました。歪みを大きくしたところ、水面のような感じが出てきたので雰囲気で色々と足してみました。
具体的には画面の半分にあたる広さのofFboを作成、通常通りにupdate内で描写の支持をします。draw内では、上半分に通常通りに描写、下半分にはofFboから取得したPixelsを元にピクセル単位で色情報にアクセス、修正を加えたものを描写しています。
[ 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 |
#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) {}; ofFbo fbo; void draw_tree(ofPoint point, float deg, int len, int depth); }; |
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 125 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofBackground(39); ofSetWindowTitle("Insta"); ofSetCircleResolution(36); this->fbo.allocate(ofGetWidth(), ofGetHeight() / 2); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->fbo.begin(); ofClear(0); // Draw Sun To Fbo ofPushMatrix(); ofTranslate(this->fbo.getWidth() / 3, this->fbo.getHeight() / 5 * 2); ofSetColor(239, 39, 39); ofDrawCircle(ofPoint(), 130); ofPopMatrix(); // Draw Firefry To Fbo ofSetColor(239, 239, 39); for (int i = 0; i < 15; i++) { int x = ofRandom(ofGetWidth()); int y = (int)(ofRandom(this->fbo.getHeight()) + ofGetFrameNum()) % (int)this->fbo.getHeight(); ofDrawCircle(x, y, 2); } // Draw Tree To Fbo ofSetColor(239); for (int i = 0; i < 60; i++) { int x = ofRandom(this->fbo.getWidth()); this->draw_tree(ofPoint(x, this->fbo.getHeight()), -90, ofRandom(30, 70), 8); } this->fbo.end(); } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); // Draw Fbo ofSetColor(255, 255); this->fbo.draw(-ofGetWidth() / 2, -ofGetHeight() / 2); // Draw Shadow ofPixels pixels; this->fbo.readToPixels(pixels); for (int y = 0; y < pixels.getHeight(); y++) { int noise_x = ofMap(ofNoise(y * 0.05 + ofGetFrameNum() * 0.05), 0, 1, -20, 20); noise_x = noise_x * ofMap(y, 0, pixels.getHeight(), 1, 0.1); if (noise_x > 0) { for (int x = pixels.getWidth() - 1; x > noise_x; x--) { pixels.setColor(x, y, pixels.getColor(x - noise_x, y)); } for (int x = 0; x < noise_x; x++) { pixels.setColor(x, y, ofColor(39)); } } else if(noise_x < 0) { for (int x = 0; x < pixels.getWidth() + noise_x; x++) { pixels.setColor(x, y, pixels.getColor(x - noise_x, y)); } for (int x = pixels.getWidth() + noise_x; x < pixels.getWidth(); x++) { pixels.setColor(x, y, ofColor(39)); } } } ofImage image; image.setFromPixels(pixels); ofRotate(180); ofRotateY(180); ofSetColor(255, 64); image.draw(-ofGetWidth() / 2, -ofGetHeight() / 2); } //-------------------------------------------------------------- void ofApp::draw_tree(ofPoint point, float deg, int len, int depth){ ofSetLineWidth(0.1 + depth / 8); ofPoint target(len * cos(deg * DEG_TO_RAD), len * sin(deg * DEG_TO_RAD)); ofDrawLine(point, point + target); if (depth > 1) { this->draw_tree(point + target, deg - ofRandom(-5, 15), len * 0.4, depth - 1); this->draw_tree(point + target, deg + ofRandom(-5, 15), len * 0.8, depth - 1); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |