[ Video ]
[ About ]
OpenCVのぼかしを使って発光っぽいのを目指す。
Glowing orb.
[ 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 |
#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; vector<glm::vec2> location_list; vector<ofColor> color_list; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openframeworks"); ofBackground(0); ofSetLineWidth(3); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->fbo.allocate(ofGetWidth(), ofGetHeight()); 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); this->location_list.clear(); this->color_list.clear(); this->fbo.begin(); ofClear(0); ofFill(); ofColor color; glm::vec2 location; for (int i = 0; i < 16; i++) { color.setHsb(ofMap(i, 0, 16, 0, 255), 255, 255); auto noise_seed = glm::vec2(ofRandom(1000), ofRandom(1000)); ofSetColor(color); for (int k = 0; k < 8; k++) { location = glm::vec2(ofMap(ofNoise(noise_seed.x, (ofGetFrameNum() + k) * 0.008), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(noise_seed.y, (ofGetFrameNum() + k) * 0.008), 0, 1, 0, ofGetHeight())); ofBeginShape(); for (int deg = 0; deg < 360; deg++) { ofVertex(location + glm::vec2(ofMap(k, 0, 8, 5, 40) * cos(deg * DEG_TO_RAD), ofMap(k, 0, 8, 5, 40) * sin(deg * DEG_TO_RAD))); } ofEndShape(true); } this->color_list.push_back(color); this->location_list.push_back(location); } this->fbo.end(); this->fbo.readToPixels(this->pixels); cv::GaussianBlur(this->pixels_mat, this->pixels_mat, cv::Size(49, 49), 50, 50); } //-------------------------------------------------------------- void ofApp::draw() { ofFill(); ofSetColor(255); ofImage draw_image; draw_image.setFromPixels(this->pixels); draw_image.draw(0, 0); for (int i = 0; i < this->location_list.size(); i++) { vector<glm::vec2> vertices; for (int deg = 0; deg < 360; deg++) { vertices.push_back(this->location_list[i] + glm::vec2(15 * cos(deg * DEG_TO_RAD), 15 * sin(deg * DEG_TO_RAD))); } ofFill(); ofSetColor(255); ofBeginShape(); ofVertices(vertices); ofEndShape(true); ofNoFill(); ofSetColor(this->color_list[i]); ofBeginShape(); ofVertices(vertices); ofEndShape(true); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |