[ Video ]
[ About ]
100フレーム後に死ぬランダムウォーク。
100 frame random workers.
[ 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 |
#pragma once #include "ofMain.h" #include "Actor.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 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<glm::vec3> location_list; vector<vector<int>> next_index_list; vector<unique_ptr<Actor>> actor_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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetLineWidth(2); ofEnableDepthTest(); auto span = 20; for (int x = -200; x <= 200; x += span) { for (int y = -200; y <= 200; 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); } } //-------------------------------------------------------------- void ofApp::update() { int frame_span = 15; int prev_index_size = 0; this->actor_list.push_back(make_unique<Actor>(this->location_list, this->next_index_list)); for (auto& actor : this->actor_list) { actor->update(frame_span, this->location_list, this->next_index_list); } for (int i = this->actor_list.size() - 1; i >= 0; i--) { if (this->actor_list[i]->isDead()) { this->actor_list.erase(this->actor_list.begin() + i); } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotate(90); ofRotateY(180); for (auto& actor : this->actor_list) { actor->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 17 18 19 20 |
#pragma once #include "ofMain.h" class Actor { public: Actor(vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list); void update(int& frame_span, vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list); void draw(); bool isDead(); private: int select_index; int next_index; int life; glm::vec3 location; std::deque<glm::vec3> log; }; |
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 |
#include "Actor.h" //-------------------------------------------------------------- Actor::Actor(vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list) { this->select_index = ofRandom(location_list.size()); this->next_index = this->select_index; this->life = 100; } //-------------------------------------------------------------- void Actor::update(int& frame_span, vector<glm::vec3>& location_list, vector<vector<int>>& next_index_list) { if (ofGetFrameNum() % frame_span == 0) { this->select_index = this->next_index; this->next_index = next_index_list[this->select_index][(int)ofRandom(next_index_list[this->select_index].size())]; } 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; this->log.push_front(this->location); while (this->log.size() > 50) { this->log.pop_back(); } this->life--; } //-------------------------------------------------------------- void Actor::draw() { ofSetColor(39); ofFill(); ofDrawCircle(this->log.front(), 3); ofNoFill(); ofBeginShape(); for (auto& l : this->log) { ofVertex(l); } ofEndShape(); } //-------------------------------------------------------------- bool Actor::isDead() { return this->life < 0; } |