[ Video ]
[ About ]
比較的簡単に、sin関数とcos関数で描ける図形を並べてみました。ちょっと高級な、箱に入ったチョコレートみたいな見た目で可愛いですね。
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#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_shape(ofPoint point, float radius, int type); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(239); ofSetWindowTitle("Insta"); ofSetColor(39); ofNoFill(); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { int size = 60; for (int x = size / 2; x < ofGetWidth() + size / 2; x += size) { for (int y = size / 2; y < ofGetHeight() + size / 2; y += size) { ofPoint point = ofPoint(x, y); float radius = (size * 0.5) * 0.8; int type = ofNoise(x * 0.005, y * 0.005) * 11; this->draw_shape(point, radius , type); int n = ofNoise(x * 0.005, y * 0.005, ofGetFrameNum() * 0.01) * 12; for (int i = 0; i < n; i++) { float mini_radius = radius - 2.5 * i; if (mini_radius < 0) { break; } this->draw_shape(point, mini_radius, type); } } } } //-------------------------------------------------------------- void ofApp::draw_shape(ofPoint point, float radius, int type) { int deg_span = 1; int rotate = 0; switch (type) { case 0: case 9: deg_span = 120; rotate = 270; break; case 1: case 8: deg_span = 90; rotate = 45; break; case 2: case 6: deg_span = 60; rotate = 30; break; case 3: case 4: case 5: deg_span = 1; break; case 10: deg_span = 30; break; } ofPushMatrix(); ofTranslate(point); ofRotate(rotate); ofBeginShape(); for (int deg = 0; deg < 360; deg += deg_span) { if (type == 10 && (deg / deg_span) % 2 == 0) { ofVertex(radius * 0.5 * cos(deg * DEG_TO_RAD), radius * 0.5 * sin(deg * DEG_TO_RAD)); } else { ofVertex(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); } } ofEndShape(true); ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |