[ Video ]
[ About ]
コーディングで蝶々を描く。
Paint a butterfly by coding.
[ 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 |
#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_butter_fly(glm::vec2 location, float size); 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 101 102 103 104 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(39); ofSetLineWidth(3); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(180); this->draw_butter_fly(glm::vec2(-180, -180), 280); this->draw_butter_fly(glm::vec2(90, -270), 90); this->draw_butter_fly(glm::vec2(270, -270), 120); this->draw_butter_fly(glm::vec2(90, -90), 130); this->draw_butter_fly(glm::vec2(270, -90), 100); this->draw_butter_fly(glm::vec2(-90, 270), 90); this->draw_butter_fly(glm::vec2(-270, 270), 120); this->draw_butter_fly(glm::vec2(-90, 90), 130); this->draw_butter_fly(glm::vec2(-270, 90), 100); this->draw_butter_fly(glm::vec2(180, 180), 280); } //-------------------------------------------------------------- void ofApp::draw_butter_fly(glm::vec2 location, float size) { ofPushMatrix(); ofTranslate(location); int param = ofRandom(1000); for (int k = 0; k < 2; k++) { ofRotateY(180); /// --- /// ofPushMatrix(); k == 0 ? ofRotateY(sin(param + ofGetFrameNum() * 0.6) * 15) : ofRotateY(cos(param + ofGetFrameNum() * 0.6) * 15); ofBeginShape(); ofVertex(glm::vec2()); ofBezierVertex(glm::vec2(0, size * -0.25), glm::vec2(size * 0.25, size * -0.5), glm::vec2(size * 0.5, size * -0.5)); ofVertex(glm::vec2(glm::vec2(size * 0.5, size * -0.5))); ofBezierVertex(glm::vec2(size * 0.55, size * -0.25), glm::vec2(size * 0.55, size * -0.25), glm::vec2(glm::vec2(size * 0.5, size * -0.05))); ofVertex(glm::vec2(size * 0.5, size * -0.05)); ofBezierVertex(glm::vec2(size * 0.25, size * 0.05), glm::vec2(size * 0.25, size * 0.01), glm::vec2(0, 0)); ofEndShape(); ofPopMatrix(); /// --- /// ofPushMatrix(); k == 0 ? ofRotateY(sin(param + ofGetFrameNum() * 0.6) * 10) : ofRotateY(cos(param + ofGetFrameNum() * 0.6) * 10); ofBeginShape(); ofVertex(glm::vec2(0, 0)); ofBezierVertex(glm::vec2(size * 0.25, size * -0.01), glm::vec2(size * 0.25, size * 0.08), glm::vec2(size * 0.35, size * 0.15)); ofVertex(glm::vec2(glm::vec2(size * 0.35, size * 0.15))); ofBezierVertex(glm::vec2(size * 0.35, size * 0.2), glm::vec2(size * 0.38, size * 0.25), glm::vec2(glm::vec2(size * 0.35, size * 0.35))); ofVertex(glm::vec2(size * 0.35, size * 0.35)); ofBezierVertex(glm::vec2(size * 0.1, size * 0.35), glm::vec2(0, size * 0.15), glm::vec2(0, 0)); ofEndShape(); ofPopMatrix(); } ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |