[ Video ]
[ About ]
計算した角度を改めて割り振りなおして、緩急をつける。
I reassign the calculated angle to make it slower and faster.
1 2 3 4 5 6 7 8 |
if (deg < 80) { deg = 0; } else if (deg < 90) { deg = ofMap(deg, 80, 90, 0, 90); } else if (deg < 170) { deg = 90; } else if (deg < 180) { deg = ofMap(deg, 170, 180, 90, 180); } else if (deg < 260) { deg = 180; } else if (deg < 270) { deg = ofMap(deg, 260, 270, 180, 270); } else if (deg < 350) { deg = 270; } else if (deg < 360) { deg = ofMap(deg, 350, 360, 270, 360); } |
[ 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) {}; void draw_MAGATAMA(glm::vec2 location, float radius, float rotate_deg, ofColor color_1, ofColor color_2); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(239); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { int radius = 20; for(int x = radius * 3; x <= ofGetWidth() - radius * 3; x += radius * 2){ for (int y = radius * 3; y <= ofGetHeight() - radius * 3; y += radius * 2) { int deg = ofMap(ofNoise(x * 0.002, y * 0.002, ofGetFrameNum() * 0.01), 0, 1, 0, 360); if (deg < 80) { deg = 0; } else if (deg < 90) { deg = ofMap(deg, 80, 90, 0, 90); } else if (deg < 170) { deg = 90; } else if (deg < 180) { deg = ofMap(deg, 170, 180, 90, 180); } else if (deg < 260) { deg = 180; } else if (deg < 270) { deg = ofMap(deg, 260, 270, 180, 270); } else if (deg < 350) { deg = 270; } else if (deg < 360) { deg = ofMap(deg, 350, 360, 270, 360); } this->draw_MAGATAMA(glm::vec2(x, y), radius * 0.9, 0 + deg, ofColor(239), ofColor(39)); this->draw_MAGATAMA(glm::vec2(x, y), radius * 0.9, 180 + deg, ofColor(39), ofColor(239)); } } } //-------------------------------------------------------------- void ofApp::draw_MAGATAMA(glm::vec2 location, float radius, float rotate_deg, ofColor color_1, ofColor color_2) { float len = radius * 0.5522; float deg = 0; ofPushMatrix(); ofTranslate(location); ofRotate(rotate_deg); vector<glm::vec2> vertices; vector<pair<glm::vec2, glm::vec2>> handle_list; vertices.push_back(glm::vec2(0, 0)); deg = 180; handle_list.push_back(make_pair<glm::vec2, glm::vec2>( glm::vec2(vertices.back() + glm::vec2(len * 0.5 * cos(deg * DEG_TO_RAD), len * 0.5 * sin(deg * DEG_TO_RAD))), glm::vec2(vertices.back() + glm::vec2(len * 0.5 * cos((deg + 180) * DEG_TO_RAD), len * 0.5 * sin((deg + 180) * DEG_TO_RAD))))); vertices.push_back(glm::vec2(radius * 0.5, radius * -0.5)); deg = 90; handle_list.push_back(make_pair<glm::vec2, glm::vec2>( glm::vec2(vertices.back() + glm::vec2(len * 0.5 * cos(deg * DEG_TO_RAD), len * 0.5 * sin(deg * DEG_TO_RAD))), glm::vec2(vertices.back() + glm::vec2(len * 0.5 * cos((deg + 180) * DEG_TO_RAD), len * 0.5 * sin((deg + 180) * DEG_TO_RAD))))); vertices.push_back(glm::vec2(0, radius * -1)); deg = 0; handle_list.push_back(make_pair<glm::vec2, glm::vec2>( glm::vec2(vertices.back() + glm::vec2(len * 0.5 * cos(deg * DEG_TO_RAD), len * 0.5 * sin(deg * DEG_TO_RAD))), glm::vec2(vertices.back() + glm::vec2(len * cos(deg * DEG_TO_RAD), len * sin(deg * DEG_TO_RAD))))); vertices.push_back(glm::vec2(radius, 0)); deg = 270; handle_list.push_back(make_pair<glm::vec2, glm::vec2>( glm::vec2(vertices.back() + glm::vec2(len * cos(deg * DEG_TO_RAD), len * sin(deg * DEG_TO_RAD))), glm::vec2(vertices.back() + glm::vec2(len * cos((deg + 180) * DEG_TO_RAD), len * sin((deg + 180) * DEG_TO_RAD))))); vertices.push_back(glm::vec2(0, radius)); deg = 0; handle_list.push_back(make_pair<glm::vec2, glm::vec2>( glm::vec2(vertices.back() + glm::vec2(len * cos(deg * DEG_TO_RAD), len * sin(deg * DEG_TO_RAD))), glm::vec2(vertices.back() + glm::vec2(len * 0.5 * cos((deg + 180) * DEG_TO_RAD), len * 0.5 * sin((deg + 180) * DEG_TO_RAD))))); vertices.push_back(glm::vec2(radius * -0.5, radius * 0.5)); deg = 90; handle_list.push_back(make_pair<glm::vec2, glm::vec2>( glm::vec2(vertices.back() + glm::vec2(len * 0.5 * cos(deg * DEG_TO_RAD), len * 0.5 * sin(deg * DEG_TO_RAD))), glm::vec2(vertices.back() + glm::vec2(len * 0.5 * cos((deg + 180) * DEG_TO_RAD), len * 0.5 * sin((deg + 180) * DEG_TO_RAD))))); ofSetColor(color_1); ofFill(); ofBeginShape(); for (int i = 0; i < vertices.size(); i++) { int n = (i + 1) % vertices.size(); ofVertex(vertices[i]); ofBezierVertex(handle_list[i].second, handle_list[n].first, vertices[n]); } ofEndShape(); ofSetColor(color_2); ofBeginShape(); for (deg = 0; deg <= 360; deg += 5) { ofVertex(glm::vec2(0, radius * 0.5) + glm::vec2(radius * 0.2 * cos(deg * DEG_TO_RAD), radius * 0.2 * sin(deg * DEG_TO_RAD))); } ofEndShape(true); ofSetColor(ofColor(39)); ofNoFill(); ofBeginShape(); for (int i = 0; i < vertices.size(); i++) { int n = (i + 1) % vertices.size(); ofVertex(vertices[i]); ofBezierVertex(handle_list[i].second, handle_list[n].first, vertices[n]); } ofNextContour(true); for (deg = 0; deg <= 360; deg += 5) { ofVertex(glm::vec2(0, radius * 0.5) + glm::vec2(radius * 0.2 * cos(deg * DEG_TO_RAD), radius * 0.2 * sin(deg * DEG_TO_RAD))); } ofEndShape(true); ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |