[ Video ]
[ About ]
矢印の線を軌跡にしてみました。Long long agoと掛けたLong long arrowというオヤジギャグを思いついて発作的に
Long long arrows.
[ 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 29 |
#pragma once #include "ofMain.h" #include "ofxBox2d.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) {} ofxBox2d box2d; vector<shared_ptr<ofxBox2dCircle>> circles; vector<deque<ofPoint>> circles_log; vector<ofPoint> force_fields; int force_field_radius; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("Insta"); ofBackground(39); ofSetColor(239); ofSetLineWidth(2); this->box2d.init(); this->box2d.setGravity(0, 0); this->box2d.createBounds(); this->box2d.setFPS(30); this->box2d.registerGrabbing(); for (int i = 0; i < 128; i++) { float radius = 15; auto circle = make_shared<ofxBox2dCircle>(); circle->setPhysics(1.0, 0.63, 1.0); circle->setup(this->box2d.getWorld(), ofRandom(ofGetWidth() / 2), ofRandom(ofGetHeight() / 2), radius); this->circles.push_back(circle); deque<ofPoint> log; this->circles_log.push_back(log); } this->force_fields.push_back(ofPoint(ofGetWidth() / 4, ofGetHeight() / 4)); this->force_fields.push_back(ofPoint(ofGetWidth() / 4 * 3, ofGetHeight() / 4)); this->force_fields.push_back(ofPoint(ofGetWidth() / 4 * 3, ofGetHeight() / 4 * 3)); this->force_fields.push_back(ofPoint(ofGetWidth() / 4, ofGetHeight() / 4 * 3)); this->force_field_radius = 300; } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); for (int i = 0; i < this->circles.size(); i++) { shared_ptr<ofxBox2dCircle> circle = this->circles[i]; ofPoint point = circle->getPosition(); for (int field_index = 0; field_index < this->force_fields.size(); field_index++) { float distance = point.distance(this->force_fields[field_index]); if (distance < this->force_field_radius) { ofPoint p = ofPoint(this->force_field_radius * cos((field_index * 90 + 10) * DEG_TO_RAD), this->force_field_radius * sin((field_index * 90 + 10) * DEG_TO_RAD)); circle->addForce(p, ofMap(distance, 0, this->force_field_radius, 0.1, 0.01)); } } } this->box2d.update(); for (int i = 0; i < this->circles.size(); i++) { this->circles_log[i].push_front(this->circles[i]->getPosition()); while (this->circles_log[i].size() > 10) { this->circles_log[i].pop_back(); } } } //-------------------------------------------------------------- void ofApp::draw() { for (int i = 0; i < this->circles.size(); i++) { float radius = this->circles[i]->getRadius(); ofPoint point = this->circles[i]->getPosition(); ofPoint velocity = this->circles[i]->getVelocity(); ofPushMatrix(); ofTranslate(point); float velocity_deg = atan2f(velocity.y, velocity.x) * RAD_TO_DEG; ofFill(); ofBeginShape(); for (int deg = velocity_deg; deg < velocity_deg + 270; deg += 120) { ofVertex(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); } ofEndShape(true); ofPopMatrix(); ofNoFill(); ofBeginShape(); for (int log_index = 0; log_index < this->circles_log[i].size(); log_index++) { ofVertex(this->circles_log[i][log_index]); } ofEndShape(false); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |