[ Video ]
[ About ]
グラデーション波紋。
Gradation ripple.
[ 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 "Ripple.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<Ripple>> ripple_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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); } //-------------------------------------------------------------- void ofApp::update() { if (ofRandom(100) < 4) { auto ripple = make_unique<Ripple>(glm::vec2(ofRandom(ofGetWidth()), ofRandom(ofGetHeight()))); this->ripple_list.push_back(move(ripple)); } for (auto& ripple : this->ripple_list) { ripple->update(); } for (int i = this->ripple_list.size() - 1; i >= 0; i--) { if (this->ripple_list[i]->isDead()) { this->ripple_list.erase(this->ripple_list.begin() + i); } } } //-------------------------------------------------------------- void ofApp::draw() { for (auto& ripple : this->ripple_list) { ripple->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 |
#pragma once #include "ofMain.h" class Ripple { public: Ripple(); Ripple(glm::vec2 location); void update(); void draw(); bool isDead(); private: glm::vec2 location; float radius; ofMesh mesh; }; |
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 |
#include "Ripple.h" //-------------------------------------------------------------- Ripple::Ripple() : Ripple(glm::vec2()) { } //-------------------------------------------------------------- Ripple::Ripple(glm::vec2 location) { this->location = location; this->radius = 0; } //-------------------------------------------------------------- void Ripple::update() { this->mesh.clear(); this->radius += 1; auto len = radius / 25 + 1; for (auto deg = 0; deg < 360; deg += 1) { auto out_radius = radius + len; auto in_location = this->location + glm::vec2(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); auto out_location = this->location + glm::vec2(out_radius * cos(deg * DEG_TO_RAD), out_radius * sin(deg * DEG_TO_RAD)); ofColor in_color, out_color; float alpha = this->radius < 250 ? 255 : ofMap(this->radius, 250, 300, 255, 0); in_color.setHsb(ofMap(ofNoise(in_location.x * 0.001, in_location.y * 0.001, ofGetFrameNum() * 0.005), 0, 1, 0, 255), 200, 255, alpha); out_color.setHsb(ofMap(ofNoise(out_location.x * 0.001, out_location.y * 0.001, ofGetFrameNum() * 0.005), 0, 1, 0, 255), 200, 255, alpha); mesh.addVertex(ofPoint(in_location)); mesh.addColor(in_color); mesh.addVertex(ofPoint(out_location)); mesh.addColor(out_color); } for (auto i = 0; i < mesh.getVertices().size(); i += 2) { auto index_0 = i; auto index_1 = (i + 1) % mesh.getVertices().size(); auto index_2 = (i + 2) % mesh.getVertices().size(); auto index_3 = (i + 3) % mesh.getVertices().size(); mesh.addIndex(index_0); mesh.addIndex(index_1); mesh.addIndex(index_2); mesh.addIndex(index_3); mesh.addIndex(index_1); mesh.addIndex(index_2); } } //-------------------------------------------------------------- void Ripple::draw() { this->mesh.draw(); } //-------------------------------------------------------------- bool Ripple::isDead() { return this->radius > 300; } |