[ Video ]
[ About ]
大きな円を小さな円で埋める動きにNoiseを加えてみました。突然消えたり・出現するやつがいるので今後の課題ですが、良い感じにうごめいてくれてる気がします。
[ 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 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_circles(ofPoint range_point, int range_radius, int number_of_circles); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); ofBackground(239); ofSetWindowTitle("Insta"); } //-------------------------------------------------------------- void ofApp::update(){ ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw(){ this->draw_circles(ofPoint(ofGetWidth() / 2, ofGetHeight() / 2), 300, 600); } //-------------------------------------------------------------- void ofApp::draw_circles(ofPoint range_point, int range_radius, int number_of_circles) { ofPushMatrix(); ofTranslate(range_point); int min = 3; int max = 35; vector<tuple<ofColor, ofPoint, float>> circles; while (circles.size() < number_of_circles) { ofPoint point = ofPoint(ofRandom(-range_radius, range_radius), ofRandom(-range_radius, range_radius)); point *= 1 + ofNoise(point.x * 0.005, point.y * 0.005, ofGetFrameNum() * 0.005); if (point.length() > range_radius) { continue; } ofColor color; color.setHsb(ofRandom(0, 255), 239, 239); float radius = ofRandom(min, max); bool flag = true; for (int i = 0; i < circles.size(); i++) { while (radius > min) { if (point.distance(get<1>(circles[i])) < get<2>(circles[i]) + radius) { radius *= 0.9; } else { break; } } if (radius < min) { flag = false; break; } } if (flag) { circles.push_back(make_tuple(color, point, radius)); } } for (int circles_index = 0; circles_index < circles.size(); circles_index++) { ofColor color = get<0>(circles[circles_index]); ofPoint point = get<1>(circles[circles_index]); float radius = get<2>(circles[circles_index]); ofSetColor(color); ofDrawCircle(point, radius); } ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |