[ Video ]
[ About ]
円周上に隙間を作らない形で円を並べたいなぁと何となく思たち。
その目的自体は割と早く作れたのですが、円周を重ねて順々に大きくしたいっ!と思った結果、ドツボにハマりました。結局、ループでちょっと(0.1)ずつ大きくして良い感じの半径を見つけるというショボい実装に…
ちなみに、動画ではNoiseで円の大きさを変えているので綺麗に並んでい姿は確認不可です。
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#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) {}; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(239); ofSetWindowTitle("Insta"); ofSetColor(39); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { int deg_span = 8; ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); ofRotate(deg_span * 0.5f); float radius = 50; float small_radius = 0; for (int i = 0; radius < 330; i++) { if (small_radius == 0) { ofPoint p1 = ofPoint(radius * cos(0), radius * sin(0)); ofPoint p2 = ofPoint(radius * cos(deg_span * DEG_TO_RAD), radius * sin(deg_span * DEG_TO_RAD)); small_radius = p1.distance(p2) * 0.5; } for (int deg = 0; deg < 360 - deg_span; deg += deg_span) { float noise_value = ofMap(ofNoise(i * 0.1, deg * 0.02 + ofGetFrameNum() * 0.03), 0, 1, 0, 1); ofPoint point = ofPoint(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); ofDrawCircle(point, small_radius * noise_value); } float next_small_radius = 0; float tmp_radius = radius; while (radius < tmp_radius + small_radius + next_small_radius) { ofPoint p1 = ofPoint(radius * cos(0), radius * sin(0)); ofPoint p2 = ofPoint(radius * cos(deg_span * DEG_TO_RAD), radius * sin(deg_span * DEG_TO_RAD)); next_small_radius = p1.distance(p2) * 0.5; radius += 0.1; } small_radius = next_small_radius; } } //======================================================================== int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |