[ Video ]
[ About ]
トーラス面の小円に対して、180度分だけ面を描写しています。それぞれの面は、大円の角度とフレーム数を加えた分だけ回転しているので、面の移動が伝播して見えるようになっています。
トーラス面は2色で構成されていますが1色を背景色と一緒にしてあるので、ちょっと不思議な感じが出ていると思います。青い玉は情報の補助として、常に見えるように大円を基準に公転しています。
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#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; ofPoint make_point(float radius, float small_radius, float deg, float small_deg); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(239); ofSetWindowTitle("Insta"); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); float radius = 300; int small_radius = 80; int deg_span = 10; int small_deg_span = 10; ofSetColor(39, 39, 139); int sphere_deg = -ofGetFrameNum() - 180; ofPoint sphere_point = ofPoint(radius * cos(sphere_deg * DEG_TO_RAD), radius * sin(sphere_deg * DEG_TO_RAD)); ofDrawSphere(sphere_point, 15); for (int deg = 0; deg < 360; deg += deg_span) { ofColor color = deg % (deg_span * 2) == 0 ? ofColor(239, 39, 39) : ofColor(239); ofSetColor(color); int start_small_deg = ofGetFrameNum() + deg; for (int small_deg = start_small_deg; small_deg < start_small_deg + 180; small_deg += small_deg_span) { ofBeginShape(); ofVertex(this->make_point(radius, small_radius, deg, small_deg)); ofVertex(this->make_point(radius, small_radius, deg + deg_span, small_deg)); ofVertex(this->make_point(radius, small_radius, deg + deg_span, small_deg + small_deg_span)); ofVertex(this->make_point(radius, small_radius, deg, small_deg + small_deg_span)); ofEndShape(true); } } this->cam.end(); } //-------------------------------------------------------------- ofPoint ofApp::make_point(float radius, float small_radius, float deg, float small_deg) { float x_1 = radius * cos(deg * DEG_TO_RAD); float y_1 = radius * sin(deg * DEG_TO_RAD); float x_2 = small_radius * cos(small_deg * DEG_TO_RAD) * cos(deg * DEG_TO_RAD); float y_2 = small_radius * cos(small_deg * DEG_TO_RAD) * sin(deg * DEG_TO_RAD); float x = x_1 + x_2; float y = y_1 + y_2; float z = small_radius * sin(small_deg * DEG_TO_RAD); return ofPoint(x, y, z); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |