[ Video ]
[ About ]
モザイクログ.
Mosaic.
[ 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 |
#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) {}; int size; vector<glm::vec2> location_list; vector<float> noise_seed_list; vector<float> noise_step_list; vector<int> param_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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetLineWidth(3); ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); this->size = 10; for (auto x = size * 0.5; x < ofGetWidth() + size * 0.5; x += size) { for (auto y = size * 0.5; y < ofGetHeight() + size * 0.5; y += size) { this->location_list.push_back(glm::vec2(x, y)); this->noise_seed_list.push_back(ofRandom(1000)); this->noise_step_list.push_back(ofRandom(1000)); this->param_list.push_back(0); } } } //-------------------------------------------------------------- void ofApp::update() { glm::vec2 noise_location = glm::vec2(ofMap(ofNoise(11, ofGetFrameNum() * 0.005), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(3, ofGetFrameNum() * 0.005), 0, 1, 0, ofGetHeight())); int index = 0; for (auto& location : location_list) { if (glm::distance(location, noise_location) < 80) { this->param_list[index] += this->param_list[index] < 100 ? 5 : 0; } else { this->param_list[index] -= this->param_list[index] > 0 ? 1 : 0; } this->noise_step_list[index] += this->param_list[index] > 0 ? ofMap(this->param_list[index], 0, 100, 0.01, 0.05) : 0; index++; } } //-------------------------------------------------------------- void ofApp::draw() { ofColor color; int index = 0; for (auto& location : location_list) { color.setHsb(ofMap(ofNoise(this->noise_seed_list[index], this->noise_step_list[index]), 0, 1, 0, 255), 180, 255); ofSetColor(color, ofMap(this->param_list[index], 0, 100, 0, 255)); ofDrawRectangle(location, this->size, this->size); index++; } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |