[ Video ]
[ About ]
繋げて繋ぎなおす。
Connect and reconnect.
[ 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" 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) {}; void draw_arc(vector<glm::vec3> vertices_1, vector<glm::vec3> vertices_2); vector<glm::vec3> location_list; vector<int> rotate_param_list; vector<int> deg_start_list; vector<int> deg_end_list; vector<bool> flag_list; 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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofEnableDepthTest(); ofSetLineWidth(2.5); int size = 120; for (int x = ofGetWidth() * -0.5 + size * 0.5; x <= ofGetWidth() * 0.5 - size * 0.5; x += size) { for (int y = ofGetHeight() * -0.5 + size * 0.5; y <= ofGetHeight() * 0.5 - size * 0.5; y += size) { this->location_list.push_back(glm::vec3(x, y, 360)); int rotate_param = ofRandom(4); this->rotate_param_list.push_back(rotate_param); this->deg_start_list.push_back(0); this->deg_end_list.push_back(90); this->flag_list.push_back(false); } } } //-------------------------------------------------------------- void ofApp::update() { for (int i = 0; i < this->location_list.size(); i++) { if (ofGetFrameNum() % 45 == 0) { if (ofRandom(100) < 10) { this->flag_list[i] = true; } } if (this->flag_list[i]) { if (this->deg_end_list[i] < 90) { this->deg_end_list[i] += 2; } else { this->deg_start_list[i] += 2; if (this->deg_start_list[i] >= 90) { this->deg_end_list[i] = 0; this->deg_start_list[i] = 0; this->rotate_param_list[i] = (this->rotate_param_list[i] + 1) % this->rotate_param_list.size(); } } if (this->deg_start_list[i] == 0 && this->deg_end_list[i] == 90) { this->flag_list[i] = false; } } } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum() * 0.25); ofRotateX(ofGetFrameNum() * 0.5); int size = 120; int radius = size * 0.5; int width = 20; for (int i = 0; i < 6; i++) { if (i < 4) { ofRotateY(90); } else if (i < 5) { ofRotateX(90); } else if (i < 6) { ofRotateX(180); } for (int i = 0; i < this->location_list.size(); i++) { ofPushMatrix(); ofTranslate(this->location_list[i].x, this->location_list[i].y); ofRotate(90 * this->rotate_param_list[i]); vector<glm::vec3> vertices_1, vertices_2; for (int deg = this->deg_start_list[i]; deg <= this->deg_end_list[i]; deg += 2) { vertices_1.push_back(glm::vec3(size * -0.5 + (radius + width) * cos(deg * DEG_TO_RAD), size * -0.5 + (radius + width) * sin(deg * DEG_TO_RAD), 360)); vertices_2.push_back(glm::vec3(size * -0.5 + (radius - width) * cos(deg * DEG_TO_RAD), size * -0.5 + (radius - width) * sin(deg * DEG_TO_RAD), 360)); } this->draw_arc(vertices_1, vertices_2); vertices_1.clear(); vertices_2.clear(); for (int deg = 180 + this->deg_start_list[i]; deg <= 180 + this->deg_end_list[i]; deg += 2) { vertices_1.push_back(glm::vec3(size * 0.5 + (radius + width) * cos(deg * DEG_TO_RAD), size * 0.5 + (radius + width) * sin(deg * DEG_TO_RAD), 360)); vertices_2.push_back(glm::vec3(size * 0.5 + (radius - width) * cos(deg * DEG_TO_RAD), size * 0.5 + (radius - width) * sin(deg * DEG_TO_RAD), 360)); } this->draw_arc(vertices_1, vertices_2); ofPopMatrix(); } } this->cam.end(); } //-------------------------------------------------------------- void ofApp::draw_arc(vector<glm::vec3> vertices_1, vector<glm::vec3> vertices_2) { ofFill(); ofSetColor(255); std::reverse(vertices_2.begin(), vertices_2.end()); ofBeginShape(); ofVertices(vertices_1); ofVertices(vertices_2); ofEndShape(true); ofNoFill(); ofSetColor(0); ofBeginShape(); ofVertices(vertices_1); ofEndShape(false); ofBeginShape(); ofVertices(vertices_2); ofEndShape(false); ofDrawLine(vertices_1[0], vertices_2[vertices_2.size() - 1]); ofDrawLine(vertices_1[vertices_1.size() - 1], vertices_2[0]); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |