[ Video ]
[ About ]
インタタンス毎にノイズに渡す引数を管理して、動きがある時だけ変化するようにする。
Manage the arguments passed to the noise for each intertanence, so that it changes only when there is movement.
1 2 3 4 |
//-------------------------------------------------------------- float Actor::getWordIndexNoiseValue() { return ofNoise(this->noise_param, this->noise_step); } |
[ 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#pragma once #include "ofMain.h" class Actor { public: Actor(vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list, vector<int>& destination_list); void update(const int& frame_span, vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list, vector<int>& destination_list); glm::vec3 getLocation(); float getWordIndexNoiseValue(); private: int select_index; int next_index; float noise_param; float noise_step; glm::vec3 location; }; 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<glm::vec3> location_list; vector<vector<int>> next_index_list; vector<int> destination_list; vector<unique_ptr<Actor>> actor_list; ofTrueTypeFont font; int font_size; vector<string> words; ofEasyCam cam; }; |
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
#include "ofApp.h" //-------------------------------------------------------------- Actor::Actor(vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list, vector<int>& destination_list) { this->select_index = ofRandom(location_list.size()); while (true) { auto itr = find(destination_list.begin(), destination_list.end(), this->select_index); if (itr == destination_list.end()) { destination_list.push_back(this->select_index); break; } this->select_index = (this->select_index + 1) % location_list.size(); } this->next_index = this->select_index; this->noise_param = ofRandom(1000); this->noise_step = ofRandom(1000); } //-------------------------------------------------------------- void Actor::update(const int& frame_span, vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list, vector<int>& destination_list) { if (ofGetFrameNum() % frame_span == 0) { auto tmp_index = this->select_index; this->select_index = this->next_index; int retry = next_index_list[this->select_index].size(); this->next_index = next_index_list[this->select_index][(int)ofRandom(next_index_list[this->select_index].size())]; while (--retry > 0) { auto destination_itr = find(destination_list.begin(), destination_list.end(), this->next_index); if (destination_itr == destination_list.end()) { if (tmp_index != this->next_index) { destination_list.push_back(this->next_index); break; } } this->next_index = next_index_list[this->select_index][(this->next_index + 1) % next_index_list[this->select_index].size()]; } if (retry <= 0) { destination_list.push_back(this->select_index); this->next_index = this->select_index; } } auto param = ofGetFrameNum() % frame_span; auto distance = location_list[this->next_index] - location_list[this->select_index]; this->location = location_list[this->select_index] + distance / frame_span * param; if (this->next_index != this->select_index) { this->noise_step += 0.05; } } //-------------------------------------------------------------- glm::vec3 Actor::getLocation() { return this->location; } //-------------------------------------------------------------- float Actor::getWordIndexNoiseValue() { return ofNoise(this->noise_param, this->noise_step); } //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(39); auto span = 30; for (int x = -240; x <= 240; x += span) { for (int y = -240; y <= 240; y += span) { this->location_list.push_back(glm::vec3(x, y, 0)); } } for (auto& location : this->location_list) { vector<int> next_index = vector<int>(); int index = -1; for (auto& other : this->location_list) { index++; if (location == other) { continue; } float distance = glm::distance(location, other); if (distance <= span) { next_index.push_back(index); } } this->next_index_list.push_back(next_index); } for (int i = 0; i < 255; i++) { this->actor_list.push_back(make_unique<Actor>(this->location_list, this->next_index_list, this->destination_list)); } this->font_size = 23; ofTrueTypeFontSettings font_settings("fonts/msgothic.ttc", this->font_size); font_settings.antialiased = true; font_settings.addRanges(ofAlphabet::Japanese); this->font.load(font_settings); this->words = { u8"あ", u8"い", u8"う", u8"え", u8"お", u8"か", u8"き", u8"く", u8"け", u8"こ", u8"さ", u8"し", u8"す", u8"せ", u8"そ", u8"た", u8"ち", u8"つ", u8"て", u8"と", u8"な", u8"に", u8"ぬ", u8"ね", u8"の", u8"は", u8"ひ", u8"ふ", u8"へ", u8"ほ", u8"ま", u8"み", u8"む", u8"め", u8"も", u8"や", u8"ゆ", u8"よ", u8"ら", u8"り", u8"る", u8"れ", u8"ろ", u8"わ", u8"を", u8"ん", }; } //-------------------------------------------------------------- void ofApp::update() { int frame_span = 30; int prev_index_size = 0; if (ofGetFrameNum() % frame_span == 0) { prev_index_size = this->destination_list.size(); } for (auto& actor : this->actor_list) { actor->update(frame_span, this->location_list, this->next_index_list, this->destination_list); } if (prev_index_size != 0) { this->destination_list.erase(this->destination_list.begin(), this->destination_list.begin() + prev_index_size); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); for (auto& actor : this->actor_list) { this->font.drawString(this->words[ofMap(actor->getWordIndexNoiseValue(), 0, 1, 0, this->words.size())], actor->getLocation().x - 15, actor->getLocation().y - 15); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |