[ Video ]
[ About ]
矢印を書きなぐる。
Write down arrows.
[ 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 |
#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 mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; void draw_arrow(glm::vec2 location, glm::vec2 target, float size, ofColor color); vector<float> source_deg_list; vector<float> target_deg_list; vector<ofColor> color_list; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofSetLineWidth(2); } //-------------------------------------------------------------- void ofApp::update() { // 配色デザイン ソフトグリーン P114 vector<ofColor> color_palette; color_palette.push_back(ofColor(97, 157, 110)); color_palette.push_back(ofColor(119, 180, 106)); color_palette.push_back(ofColor(143, 173, 91)); color_palette.push_back(ofColor(145, 195, 161)); color_palette.push_back(ofColor(93, 169, 145)); color_palette.push_back(ofColor(255, 255, 255)); color_palette.push_back(ofColor(131, 193, 215)); color_palette.push_back(ofColor(249, 229, 128)); auto source_deg = ofRandom(360); auto target_deg = source_deg + ofRandom(45, 315); this->source_deg_list.push_back(source_deg); this->target_deg_list.push_back(target_deg); this->color_list.push_back(color_palette[ofRandom(color_palette.size())]); while (this->source_deg_list.size() > 80) { this->source_deg_list.erase(this->source_deg_list.begin()); this->target_deg_list.erase(this->target_deg_list.begin()); this->color_list.erase(this->color_list.begin()); } } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWindowSize() * 0.5); float radius = 250; for(int i = 0; i < this->source_deg_list.size(); i++){ auto base_location = glm::vec2(radius * cos(source_deg_list[i] * DEG_TO_RAD), radius * sin(source_deg_list[i] * DEG_TO_RAD)); auto color = this->color_list[i]; color.setHsb(color.getHue(), color.getSaturation(), ofMap(i, 0, 80, 0, 255)); this->draw_arrow(base_location, glm::vec2(radius * cos(target_deg_list[i] * DEG_TO_RAD), radius * sin(target_deg_list[i] * DEG_TO_RAD)), 30, color); } } //-------------------------------------------------------------- void ofApp::draw_arrow(glm::vec2 location, glm::vec2 target, float size, ofColor color) { auto angle = std::atan2(target.y - location.y, target.x - location.x); auto distance = glm::distance(target, location); ofPushMatrix(); ofTranslate(target); ofSetColor(color); ofFill(); ofBeginShape(); ofVertex(glm::vec2(size * cos(angle), size * sin(angle))); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5))); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5))); ofEndShape(); ofBeginShape(); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.5); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.5 - glm::vec2(distance * cos(angle), distance * sin(angle))); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.5 - glm::vec2(distance * cos(angle), distance * sin(angle))); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.5); ofEndShape(); ofSetColor(0); ofNoFill(); ofBeginShape(); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.5); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5))); ofVertex(glm::vec2(size * cos(angle), size * sin(angle))); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5))); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.5); ofEndShape(); ofBeginShape(); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.5); ofVertex(glm::vec2(size * 0.5 * cos(angle - PI * 0.5), size * 0.5 * sin(angle - PI * 0.5)) * 0.5 - glm::vec2(distance * cos(angle), distance * sin(angle))); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.5 - glm::vec2(distance * cos(angle), distance * sin(angle))); ofVertex(glm::vec2(size * 0.5 * cos(angle + PI * 0.5), size * 0.5 * sin(angle + PI * 0.5)) * 0.5); ofEndShape(); ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |