[ Video ]
[ About ]
踊る貝。「数学デッサン教室 描いて楽しむ数学のかたち」によると一つの式から色々な貝が描けるらしい。面白い!
Dancing shell.
[ 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 windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; glm::vec3 make_shell_point(float a, float b, float c, float h, float k, float u, float v, float w, int R); ofEasyCam cam; vector<vector<glm::vec3>> verticesList; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofSetColor(255); ofNoFill(); ofSetLineWidth(0.5); ofEnableDepthTest(); // Parameter reference by https://twitter.com/ru_sack/status/798308368007892992 float a = 1.25; float b = 1.25; float c = 1.0; float h = 3.5; float k = 0; float w = 0.12; int R = 1; int scale = 100; float u_step = 0.15; int v_step = 15; for (float u = -35; u <= -1; u += u_step) { for (int v = 0; v <= 360; v += v_step) { vector<glm::vec3> vertices; vertices.push_back(this->make_shell_point(a, b, c, h, k, u + u_step * 0.5, (v + v_step * 0.5) * DEG_TO_RAD, w, R) * scale); vertices.push_back(this->make_shell_point(a, b, c, h, k, u + u_step * 0.5, (v - v_step * 0.5) * DEG_TO_RAD, w, R) * scale); vertices.push_back(this->make_shell_point(a, b, c, h, k, u - u_step * 0.5, (v - v_step * 0.5) * DEG_TO_RAD, w, R) * scale); vertices.push_back(this->make_shell_point(a, b, c, h, k, u - u_step * 0.5, (v + v_step * 0.5) * DEG_TO_RAD, w, R) * scale); this->verticesList.push_back(vertices); } } } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); int sound_index = 0; for (auto vertices : this->verticesList) { ofBeginShape(); for (auto vertex : vertices) { float noise_value = ofMap(ofNoise(vertex.x * 0.005, vertex.y * 0.005, vertex.z * 0.005, ofGetFrameNum() * 0.05), 0, 1, 0.8, 1.0); ofVertex(vertex * noise_value); } ofEndShape(true); } this->cam.end(); } //-------------------------------------------------------------- glm::vec3 ofApp::make_shell_point(float a, float b, float c, float h, float k, float u, float v, float w, int R) { // 数学デッサン教室 描いて楽しむ数学たち 貝殻の形 shape of shell P.59 float x = (h + a * cos(v)) * exp(w * u) * cos(c * u); float y = R * (h + a * cos(v)) * exp(w * u) * sin(c * u); float z = (k + b * sin(v)) * exp(w * u); return glm::vec3(x, y, z); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |