[ Video ]
[ About ]
円の中に円を二つ書くという再帰の関数を書いてみました。風邪が中々、後を引いており、省エネ運転続行中。。。
[ 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 |
#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) {}; ofEasyCam cam; void drawCircle(int level, ofPoint point, float radius); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofNoFill(); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->drawCircle(2, ofPoint(ofGetWidth() / 4, ofGetHeight() / 4), ofGetWidth() / 4); this->drawCircle(3, ofPoint(ofGetWidth() / 4 * 3, ofGetHeight() / 4), ofGetWidth() / 4); this->drawCircle(4, ofPoint(ofGetWidth() / 4, ofGetHeight() / 4 * 3), ofGetWidth() / 4); this->drawCircle(5, ofPoint(ofGetWidth() / 4 * 3, ofGetHeight() / 4 * 3), ofGetWidth() / 4); } //-------------------------------------------------------------- void ofApp::drawCircle(int level, ofPoint point, float radius) { if (level > 0) { float deg = ofGetFrameNum() * (6 - level); ofPoint point_1 = ofPoint(point.x + (radius / 2) * cos(deg * DEG_TO_RAD), point.y + (radius / 2) * sin(deg * DEG_TO_RAD)); ofPoint point_2 = ofPoint(point.x - (radius / 2) * cos(deg * DEG_TO_RAD), point.y - (radius / 2) * sin(deg * DEG_TO_RAD)); this->drawCircle(level - 1, point_1, radius / 2); this->drawCircle(level - 1, point_2, radius / 2); } ofPushMatrix(); ofTranslate(point); ofBeginShape(); for (int deg = 0; deg <= 360; deg += 1) { float x = radius * cos(deg * DEG_TO_RAD); float y = radius * sin(deg * DEG_TO_RAD); ofVertex(x, y); } ofEndShape(); ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |