[ Video ]
[ About ]
立方体でらせんを考えてみる。
Spiral cube.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#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) {}; 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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); ofSetLineWidth(2); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); auto len = 150; auto gap = 0.05; vector<glm::vec3> vertices; for (int i = 0; i < 100; i++) { if (i == 0) { vertices.push_back(glm::vec3(-len, len, -len)); vertices.push_back(glm::vec3(len, len, -len)); vertices.push_back(glm::vec3(len, len, len)); vertices.push_back(glm::vec3(-len, len, len)); vertices.push_back(glm::vec3(-len, -len, -len)); vertices.push_back(glm::vec3(len, -len, -len)); vertices.push_back(glm::vec3(len, -len, len)); vertices.push_back(glm::vec3(-len, -len, len)); } else { vector<glm::vec3> tmp; tmp.push_back((vertices[1] - vertices[0]) * gap + (vertices[4] - vertices[0]) * gap * 0.5 + vertices[0]); tmp.push_back((vertices[2] - vertices[1]) * gap + (vertices[5] - vertices[1]) * gap * 0.5 + vertices[1]); tmp.push_back((vertices[3] - vertices[2]) * gap + (vertices[6] - vertices[2]) * gap * 0.5 + vertices[2]); tmp.push_back((vertices[0] - vertices[3]) * gap + (vertices[7] - vertices[3]) * gap * 0.5 + vertices[3]); tmp.push_back((vertices[5] - vertices[4]) * gap + (vertices[0] - vertices[4]) * gap * 0.5 + vertices[4]); tmp.push_back((vertices[6] - vertices[5]) * gap + (vertices[1] - vertices[5]) * gap * 0.5 + vertices[5]); tmp.push_back((vertices[7] - vertices[6]) * gap + (vertices[2] - vertices[6]) * gap * 0.5 + vertices[6]); tmp.push_back((vertices[4] - vertices[7]) * gap + (vertices[3] - vertices[7]) * gap * 0.5 + vertices[7]); for (int i = 0; i < 8; i++) { ofDrawLine(vertices[i], tmp[i]); } vertices = tmp; } if (i == 0 || ofGetFrameNum() % 20 == i % 20) { ofSetLineWidth(2); ofDrawLine(vertices[0], vertices[1]); ofDrawLine(vertices[1], vertices[2]); ofDrawLine(vertices[2], vertices[3]); ofDrawLine(vertices[3], vertices[0]); ofDrawLine(vertices[4], vertices[5]); ofDrawLine(vertices[5], vertices[6]); ofDrawLine(vertices[6], vertices[7]); ofDrawLine(vertices[7], vertices[4]); ofDrawLine(vertices[0], vertices[4]); ofDrawLine(vertices[1], vertices[5]); ofDrawLine(vertices[2], vertices[6]); ofDrawLine(vertices[3], vertices[7]); for (auto& vertex : vertices) { ofDrawSphere(vertex, ofMap(i, 0, 100, 3, 0.5)); } ofSetLineWidth(1); } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |