[ Video ]
[ About ]
影の重ね。
Layering of shadows.
[ 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 |
#pragma once #include "ofMain.h" #include "opencv2/opencv.hpp" 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; ofPixels pixels; cv::Mat pixels_mat; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openframeworks"); ofBackground(239); this->fbo.allocate(ofGetWidth() + 25, ofGetHeight() + 25); this->fbo.readToPixels(this->pixels); this->pixels_mat = cv::Mat(this->pixels.getHeight(), this->pixels.getWidth(), CV_8UC4, this->pixels.getData()); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { for (int radius = 240; radius > 0; radius -= 60) { int deg_start = ofRandom(360) + ofGetFrameNum() * ofRandom(2, 4); vector<glm::vec2> vertices; for (int deg = deg_start; deg < deg_start + 360; deg += 90) { vertices.push_back(glm::vec2(ofGetWidth() * 0.5 + radius * cos(deg * DEG_TO_RAD), ofGetHeight() * 0.5 + radius * sin(deg * DEG_TO_RAD))); } // 影 this->fbo.begin(); ofClear(0); ofSetColor(0); ofFill(); ofBeginShape(); ofVertices(vertices); ofEndShape(true); ofPopMatrix(); this->fbo.end(); this->fbo.readToPixels(this->pixels); cv::GaussianBlur(this->pixels_mat, this->pixels_mat, cv::Size(11, 11), 10, 10); // 実体 this->fbo.begin(); ofClear(0); ofSetColor(239); ofBeginShape(); ofVertices(vertices); ofEndShape(true); ofSetColor(39); ofNoFill(); ofBeginShape(); ofVertices(vertices); ofEndShape(true); this->fbo.end(); // 描写 ofSetColor(255); ofImage draw_image; draw_image.setFromPixels(this->pixels); draw_image.draw(-5, -5); this->fbo.draw(-15, -15); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(512, 512, OF_WINDOW); ofRunApp(new ofApp()); } |