[ 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 26 27 28 |
#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_circle_packing(glm::vec2, float, vector<ofColor>); ofEasyCam cam; float random_seed; vector<glm::vec2> location_list; vector<float> radus_list; }; |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openframeworks"); ofBackground(0); ofNoFill(); this->random_seed = ofRandom(1000); } //-------------------------------------------------------------- void ofApp::update() { if (ofGetFrameNum() % 90 < 5) { this->random_seed = ofRandom(1000); } ofSeedRandom(this->random_seed); } //-------------------------------------------------------------- void ofApp::draw() { ofPushMatrix(); ofTranslate(ofGetWindowSize() * 0.5); vector<ofColor> color_palette; color_palette.push_back(ofColor(255, 0, 0)); color_palette.push_back(ofColor(0, 255, 0)); color_palette.push_back(ofColor(0, 0, 255)); color_palette.push_back(ofColor(255, 255, 0)); color_palette.push_back(ofColor(255, 0, 255)); color_palette.push_back(ofColor(0, 255, 255)); auto number_of_sphere = 150; vector<glm::vec2> location_list; vector<float> radius_list; while (location_list.size() < number_of_sphere) { auto location = glm::vec2(ofRandom(-300, 300), ofRandom(-300, 300)); auto radius = ofRandom(8, 80); bool flag = true; for (int i = 0; i < location_list.size(); i++) { if (glm::distance(location, location_list[i]) < (radius + radius_list[i]) * 0.85) { flag = false; break; } } if (flag) { location_list.push_back(location); radius_list.push_back(radius); ofPushMatrix(); ofTranslate(location); int color_index = ofRandom(color_palette.size()); ofFill(); ofSetColor(color_palette[color_index], 64); ofBeginShape(); for (int deg = 0; deg < 360; deg += 1) { auto noise_value = ofNoise(location.x + cos(deg * DEG_TO_RAD) * 2.5, location.y + sin(deg * DEG_TO_RAD) * 2.5, ofGetFrameNum() * 0.005); ofVertex(radius * noise_value * cos(deg * DEG_TO_RAD), radius * noise_value * sin(deg * DEG_TO_RAD)); } ofEndShape(true); ofNoFill(); ofSetColor(color_palette[color_index]); ofBeginShape(); for (int deg = 0; deg < 360; deg += 1) { auto noise_value = ofNoise(location.x + cos(deg * DEG_TO_RAD) * 2.5, location.y + sin(deg * DEG_TO_RAD) * 2.5, ofGetFrameNum() * 0.005); ofVertex(radius * noise_value * cos(deg * DEG_TO_RAD), radius * noise_value * sin(deg * DEG_TO_RAD)); } ofEndShape(true); ofPopMatrix(); } } ofPopMatrix(); } //-------------------------------------------------------------- void ofApp::draw_circle_packing(glm::vec2 location, float radius, vector<ofColor> color_palette) { auto number_of_sphere = radius * 0.8; vector<glm::vec2> location_list; vector<float> radius_list; while (location_list.size() < number_of_sphere) { auto tmp_deg = ofRandom(0, 360); auto noise_radius = ofMap(ofNoise(radius * cos(tmp_deg * DEG_TO_RAD) * 0.005, radius * sin(tmp_deg * DEG_TO_RAD) * 0.005, ofGetFrameNum() * 0.01), 0, 1, radius * 0.5, radius * 1.2); auto tmp_location_radius = ofRandom(1, noise_radius); auto tmp_location = glm::vec2(location.x + tmp_location_radius * cos(tmp_deg * DEG_TO_RAD), location.y + tmp_location_radius * sin(tmp_deg * DEG_TO_RAD)); auto tmp_radius = ofRandom(radius * 0.003, radius * 0.22); bool flag = true; for (int i = 0; i < location_list.size(); i++) { if (glm::distance(tmp_location, location_list[i]) < tmp_radius + radius_list[i] + 1) { flag = false; break; } } if (flag) { location_list.push_back(tmp_location); radius_list.push_back(tmp_radius); ofPushMatrix(); ofTranslate(tmp_location); int color_index = ofRandom(color_palette.size()); ofFill(); ofSetColor(color_palette[color_index], 100); ofBeginShape(); for (int deg = 0; deg < 360; deg += 1) { auto noise_value = ofNoise(tmp_location.x + tmp_radius * cos(deg * DEG_TO_RAD) * 0.05, tmp_location.y + tmp_radius * sin(deg * DEG_TO_RAD) * 0.05); ofVertex(tmp_radius * noise_value * cos(deg * DEG_TO_RAD), tmp_radius * noise_value * sin(deg * DEG_TO_RAD)); } ofEndShape(true); ofNoFill(); ofSetColor(color_palette[color_index]); ofBeginShape(); for (int deg = 0; deg < 360; deg += 1) { auto noise_value = ofNoise(tmp_location.x + tmp_radius * cos(deg * DEG_TO_RAD) * 0.05, tmp_location.y + tmp_radius * sin(deg * DEG_TO_RAD) * 0.05); ofVertex(tmp_radius * noise_value * cos(deg * DEG_TO_RAD), tmp_radius * noise_value * sin(deg * DEG_TO_RAD)); } ofEndShape(true); ofPopMatrix(); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |