[ Video ]
[ About ]
穴あき。
There is hole.
[ 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 |
#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 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; float random_seed; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(255); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { if (ofGetFrameNum() % 60 == 0) { this->random_seed = ofRandom(1000); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum()); ofColor color; ofSeedRandom(this->random_seed); ofFill(); for (int z = -150; z <= 150; z += 150) { color.setHsb(ofRandom(255), 180, 255); ofSetColor(color); ofPushMatrix(); ofTranslate(0, 0, z); vector<glm::vec2> location_list; vector<float> radius_list; while (location_list.size() < 120) { int x = ofRandom(-320, 320); int y = ofRandom(-320, 320); glm::vec2 location = glm::vec2(x, y); float radius = ofRandom(10, 120); if (location.x + radius > 320 || location.x - radius < -320 || location.y + radius > 320 || location.y - radius < -320) { continue; } bool flag = true; for (int i = 0; i < location_list.size(); i++) { if (glm::distance(location, location_list[i]) < radius_list[i] + radius) { flag = false; break; } } if (flag) { location_list.push_back(location); radius_list.push_back(radius); } } ofBeginShape(); ofVertex(glm::vec2(-360, -360)); ofVertex(glm::vec2(-360, 360)); ofVertex(glm::vec2(360, 360)); ofVertex(glm::vec2(360, -360)); for (int i = 0; i < location_list.size(); i++) { ofNextContour(true); for (int deg = 0; deg < 360; deg += 10) { ofVertex(location_list[i] + glm::vec2(radius_list[i] * cos(deg * DEG_TO_RAD), radius_list[i] * sin(deg * DEG_TO_RAD))); } } ofEndShape(true); ofPopMatrix(); } ofSeedRandom(this->random_seed); ofNoFill(); ofSetColor(0); for (int z = -150; z <= 150; z += 150) { color.setHsb(ofRandom(255), 180, 255); // Randomのため、演算だけ ofPushMatrix(); ofTranslate(0, 0, z); vector<glm::vec2> location_list; vector<float> radius_list; while (location_list.size() < 120) { int x = ofRandom(-320, 320); int y = ofRandom(-320, 320); glm::vec2 location = glm::vec2(x, y); float radius = ofRandom(10, 120); if (location.x + radius > 320 || location.x - radius < -320 || location.y + radius > 320 || location.y - radius < -320) { continue; } bool flag = true; for (int i = 0; i < location_list.size(); i++) { if (glm::distance(location, location_list[i]) < radius_list[i] + radius) { flag = false; break; } } if (flag) { location_list.push_back(location); radius_list.push_back(radius); } } ofBeginShape(); ofVertex(glm::vec2(-360, -360)); ofVertex(glm::vec2(-360, 360)); ofVertex(glm::vec2(360, 360)); ofVertex(glm::vec2(360, -360)); for (int i = 0; i < location_list.size(); i++) { ofNextContour(true); for (int deg = 0; deg < 360; deg += 10) { ofVertex(location_list[i] + glm::vec2(radius_list[i] * cos(deg * DEG_TO_RAD), radius_list[i] * sin(deg * DEG_TO_RAD))); } } ofEndShape(true); ofPopMatrix(); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |