[ Video ]
[ About ]
中央の円の半径は一番近い円との距離
The radius of the center circle is the distance from the nearest circle.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#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) {} }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetLineWidth(2); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { vector<glm::vec2> locations; for (int i = 0; i < 25; i++) { auto location = glm::vec2( ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.003), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.003), 0, 1, 0, ofGetHeight())); locations.push_back(location); } auto radius = 20.f; for (int i = 0; i < locations.size(); i++) { auto min_distance = 100.f; for (int k = 0; k < locations.size(); k++) { if (i == k) { continue; } auto angle_i = std::atan2(locations[k].y - locations[i].y, locations[k].x - locations[i].x); auto satellite_point_i = locations[i] + glm::vec2(radius * cos(angle_i), radius * sin(angle_i)); auto angle_k = std::atan2(locations[i].y - locations[k].y, locations[i].x - locations[k].x); auto satellite_point_k = locations[k] + glm::vec2(radius * cos(angle_k), radius * sin(angle_k)); auto distance = glm::distance(satellite_point_i, satellite_point_k); if (distance < 100) { ofSetColor(39, ofMap(distance, 0, 100, 255, 0)); ofDrawLine(satellite_point_i, satellite_point_k); ofDrawCircle(satellite_point_i, radius * 0.3); if (distance < min_distance) { min_distance = distance; } } } ofSetColor(39); ofNoFill(); ofDrawCircle(locations[i], radius); ofFill(); ofDrawCircle(locations[i], ofMap(min_distance, 0, 100, radius * 0.7, 0)); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |