[ Video ]
[ About ]
相手との位置関係を把握しながら近づいたら線を引く
Visualized Relationship.
[ 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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); ofSetLineWidth(2); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { vector<glm::vec2> locations; vector<ofColor> colors; for (int i = 0; i < 7; 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); ofColor color; color.setHsb(ofMap(i, 0, 7, 0, 255), 255, 255); colors.push_back(color); } auto radius = 30.f; for (int i = 0; i < locations.size(); i++) { ofSetColor(colors[i]); ofNoFill(); ofDrawCircle(locations[i], radius); ofFill(); ofDrawCircle(locations[i], radius * 0.5); 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); ofSetColor(colors[i], ofMap(distance, 0, 300, 255, 0)); ofDrawLine(satellite_point_i, satellite_point_k); ofSetColor(colors[k]); ofDrawCircle(satellite_point_i, radius * 0.2); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |