[ Video ]
[ About ]
keynoteの「色相の中間」というワードとソースが引っかかっていたので、とりあえず自分で作ってみる。パーティクルの中心側が自身の色、周りの色は最も近いパーティクルとの色相の中間色(になっていたらいいな)
Particle center color is original color. outor color is middle of hue of nearest particle.
[ 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#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; ofColor color; vector<ofColor> origin_colors; vector<ofColor> mix_colors; for (int i = 0; i < 20; i++) { glm::vec2 location = glm::vec2(ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.001), 0, 1, 0, ofGetWidth()), ofMap(ofNoise(ofRandom(1000), ofGetFrameNum() * 0.001), 0, 1, 0, ofGetHeight())); locations.push_back(location); color.setHsb(ofRandom(255), 255, 255); origin_colors.push_back(color); mix_colors.push_back(color); } for (int i = 0; i < locations.size(); i++) { int nearest_index = i; float nearest_distance = 150; for (int k = 0; k < locations.size(); k++) { float distance = glm::distance(locations[i], locations[k]); if (i != k && distance < nearest_distance) { nearest_index = k; nearest_distance = distance; } } ofSetColor(origin_colors[i]); ofDrawLine(locations[i], locations[nearest_index]); if (i != nearest_index) { float min_hue = min(origin_colors[i].getHue(), origin_colors[nearest_index].getHue()); float max_hue = max(origin_colors[i].getHue(), origin_colors[nearest_index].getHue()); float distance = max_hue - min_hue; if (distance < 128) { mix_colors[i].setHue((min_hue + max_hue) / 2); } else { mix_colors[i].setHue((min_hue + max_hue) / 2 - 128); } } } for (int i = 0; i < locations.size(); i++) { ofSetColor(mix_colors[i]); ofDrawCircle(locations[i], 35); ofSetColor(origin_colors[i]); ofDrawCircle(locations[i], 25); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |