[ Video ]
[ About ]
Sunshine.
[ 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 |
#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) {}; ofMesh frame; vector<vector<glm::vec3>> log_list; vector<glm::vec3> direction_list; vector<int> param_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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofSetLineWidth(5); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->frame.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { this->frame.clear(); for (int i = 0; i < 3; i++) { auto direction = 5 * glm::normalize(glm::vec3(ofRandom(-1, 1), ofRandom(-1, 1), 0)); vector<glm::vec3> log; ofColor color; color.setHsb(ofRandom(255), 255, 230); log.push_back(direction * 10); this->log_list.push_back(log); this->direction_list.push_back(direction); this->param_list.push_back(512); this->color_list.push_back(color); } for (int i = 0; i < this->log_list.size(); i++) { auto location = this->log_list[i].back() + this->direction_list[i]; this->log_list[i].push_back(location); } for (int i = 0; i < this->log_list.size(); i++) { int index = this->frame.getNumVertices(); this->frame.addVertices(this->log_list[i]); this->param_list[i] -= 2; for (int k = index; k < this->frame.getNumVertices() - 1; k++) { this->frame.addIndex(k); this->frame.addIndex(k + 1); } ofColor color = this->param_list[i] > 255 ? this->color_list[i] : ofColor(this->color_list[i], ofMap(this->param_list[i], 0, 255, 0, 255)); for (int k = index; k < this->frame.getNumVertices(); k++) { this->frame.addColor(color); } } for (int i = this->log_list.size() - 1; i >= 0; i--) { if (this->param_list[i] <= 0) { this->log_list.erase(this->log_list.begin() + i); this->direction_list.erase(this->direction_list.begin() + i); this->param_list.erase(this->param_list.begin() + i); this->color_list.erase(this->color_list.begin() + i); } } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); this->frame.drawWireframe(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |