[ Video ]
[ About ]
ランダムウォークの動きを円周の周囲で制限する。
Limit the random walk movement around the circumference.
[ 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 |
#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) {}; vector<float> radius_list; vector<vector<glm::vec2>> base_location_group_list; vector<vector<glm::vec2>> log_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 97 98 99 100 101 102 103 104 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofNoFill(); ofSetCircleResolution(72); for (int radius = 50; radius <= 250; radius += 100) { vector<glm::vec2> base_location_group; for (float deg = 0; deg < 360; deg += 5) { auto location = glm::vec2(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); base_location_group.push_back(location); } this->base_location_group_list.push_back(base_location_group); } } //-------------------------------------------------------------- void ofApp::update() { this->log_list.clear(); for (auto& base_location_group : this->base_location_group_list) { for (auto& base_location : base_location_group) { vector<glm::vec2> log; log.push_back(glm::vec2(base_location)); this->log_list.push_back(log); } } int step = 1; for (int i = 0; i < this->log_list.size(); i++) { int k = 0; int group = i / 72; int radius = 50 + 100 * group; while (true) { auto deg = ofMap(ofNoise(glm::vec4(radius, this->log_list[i].back() * 0.0035, ofGetFrameNum() * ofMap(group, 0, 5, 0.003, 0.008) + k * 0.0005)), 0, 1, -360, 360); auto next = this->log_list[i].back() + glm::vec2(step * cos(deg * DEG_TO_RAD), step * sin(deg * DEG_TO_RAD)); auto length = glm::length(next); if (length > radius - 40 && length < radius + 40) { this->log_list[i].push_back(next); } else { break; } k++; } } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWindowSize() * 0.5); ofColor color; for (int i = 0; i < this->log_list.size(); i++) { ofSetLineWidth(1.2); int group = i / 72; color.setHsb(ofMap(group, 0, 3, 0, 255), 255, 255); ofSetColor(color); if (this->log_list[i].size() > 1) { ofNoFill(); ofBeginShape(); ofVertices(this->log_list[i]); ofEndShape(); } int radius = 50 + 100 * group; ofDrawCircle(glm::vec2(), radius); ofSetLineWidth(3); ofDrawCircle(glm::vec2(), radius - 40); ofDrawCircle(glm::vec2(), radius + 40); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |