[ Video ]
[ About ]
NGK2018Bというイベントでライフゲームの3D版(unity)を発表されていた方がいたので自分もopenFrameworksでやってみた。けども何か違う…うむむ
Life Game 3D Edition.
[ 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" #include "Particle.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) {}; ofEasyCam cam; int len; vector<vector<vector<bool>>> values; vector<vector<vector<bool>>> tmp_values; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofEnableDepthTest(); this->len = 10; this->values = vector<vector<vector<bool>>>(this->len, vector<vector<bool>>(this->len, vector<bool>(this->len))); this->tmp_values = this->values; for (int x = 0; x < this->len; x++) { for (int y = 0; y < this->len; y++) { for (int z = 0; z < this->len; z++) { this->values[x][y][z] = ofRandom(2) < 1.0 ? true : false; } } } } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); if (ofGetFrameNum() % 15 != 0) { return; } for (int x = 0; x < this->len; x++) { for (int y = 0; y < this->len; y++) { for (int z = 0; z < this->len; z++) { int count = 0; int t = 0; for (int tmp_x = x - 1; tmp_x <= x + 1; tmp_x++) { for (int tmp_y = y - 1; tmp_y <= y + 1; tmp_y++){ for (int tmp_z = z - 1; tmp_z <= z + 1; tmp_z++) { if (x == tmp_x && y == tmp_y && z == tmp_z) { continue; } if (tmp_x < 0 || tmp_x > this->len - 1 || tmp_y < 0 || tmp_y > this->len - 1 || tmp_z < 0 || tmp_z > this->len - 1) { continue; } if (this->values[tmp_x][tmp_y][tmp_z]) { count++; } } } } if (count == 5) { this->tmp_values[x][y][z] = true; } else if (count >= 3 && count <= 6) { this->tmp_values[x][y][z] = this->values[x][y][z]; } else{ this->tmp_values[x][y][z] = false; } } } } this->values = this->tmp_values; } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum() * 0.5); int box_size = 25; ofColor color; for (int x = 0; x < this->len; x++) { for (int y = 0; y < this->len; y++) { for (int z = 0; z < this->len; z++) { color.setHsb(ofRandom(255), 255, 255); if (this->values[x][y][z]) { ofFill(); ofSetColor(39); ofDrawBox(x * box_size - box_size * this->len * 0.45, y * box_size - box_size * this->len * 0.45, z * box_size - box_size * this->len * 0.45, box_size * 0.95); ofSetColor(255); ofNoFill(); ofDrawBox(x * box_size - box_size * this->len * 0.45, y * box_size - box_size * this->len * 0.45, z * box_size - box_size * this->len * 0.45, box_size * 0.95 + 1); } } } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |