[ Video ]
[ About ]
noise関数の結果により、Rippleインスタンスを追加しています。
ある程度(画面サイズの2倍)大きくなったインスタンスは削除しています。
[ 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 "Ripple.h" class ofApp : public ofBaseApp{ public: ~ofApp(); 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 mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofEasyCam cam; vector<Ripple*> ripples; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- ofApp::~ofApp(){ for (int i = this->ripples.size() - 1; i > -1; i--) { delete this->ripples[i]; this->ripples.erase(this->ripples.begin() + i); } } //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofBackground(255); ofSetWindowTitle("Insta"); ofSetCircleResolution(360); ofSetLineWidth(3); } //-------------------------------------------------------------- void ofApp::update(){ for(int i = this->ripples.size() - 1; i > -1; i--){ this->ripples[i]->update(); if (this->ripples[i]->isDead()) { delete this->ripples[i]; this->ripples.erase(this->ripples.begin() + i); } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofColor body_color; body_color.setHsb(ofGetFrameNum() % 255, 255, 255); ofFill(); ofSetColor(body_color); ofDrawCircle(0, 0, 100); if (ofNoise(ofGetFrameNum() * 0.05) > 0.5) { this->ripples.push_back(new Ripple(body_color)); } for (Ripple* r : this->ripples) { r->draw(); } this->cam.end(); } //-------------------------------------------------------------- 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 |
#pragma once #include "ofMain.h" class Ripple{ public: Ripple(); Ripple(ofColor body_color); ~Ripple(); void update(); void draw(); bool isDead(); private: float radius; ofColor body_color; }; |
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 |
#include "Ripple.h" Ripple::Ripple() : Ripple(ofColor(128)){ } Ripple::Ripple(ofColor body_color) { this->radius = 100; this->body_color = body_color; } Ripple::~Ripple(){ } void Ripple::update() { this->radius += 3; } void Ripple::draw() { ofNoFill(); ofSetColor(this->body_color); ofDrawCircle(ofVec3f(0, 0, 0), this->radius); } bool Ripple::isDead() { return this->radius > ofGetWidth() || this->radius > ofGetHeight(); } |