[ Video ]
[ About ]
IcoSphereから取得した三角形(Mesh)座標の中心を繋げると、球体上の六角形の座標に!
Sphere by Hexagon.
[ 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 |
#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) {}; ofEasyCam cam; vector<ofPoint> locations; vector<vector<ofPoint>> next_points; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); ofSetLineWidth(1.5); ofEnableDepthTest(); ofIcoSpherePrimitive ico_sphere = ofIcoSpherePrimitive(300, 2); vector<ofMeshFace> triangles = ico_sphere.getMesh().getUniqueFaces(); for (int i = 0; i < triangles.size(); i++) { ofPoint average = (triangles[i].getVertex(0) + triangles[i].getVertex(1) + triangles[i].getVertex(2)) / 3; this->locations.push_back(average); } for (int i = 0; i < this->locations.size(); i++) { vector<ofPoint> next_point = vector<ofPoint>(); for (int j = 0; j < this->locations.size(); j++) { if (i == j || next_point.size() >= 3) { continue; } float distance = this->locations[i].distance(this->locations[j]); if (distance < 60) { next_point.push_back(this->locations[j]); } } this->next_points.push_back(next_point); } } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum() * 0.5); for (int location_index = 0; location_index < this->locations.size(); location_index++) { ofPoint location = this->locations[location_index]; float location_noise = ofNoise(location.x * 0.03, location.y * 0.03, ofGetFrameNum() * 0.005); for (int next_index = 0; next_index < this->next_points[location_index].size(); next_index++) { ofPoint next_point = this->next_points[location_index][next_index]; ofPoint distance = next_point - location; distance = distance.normalize() * ofMap(location_noise, 0, 1, 0, distance.length() * 0.65); ofDrawLine(location, location + distance); } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |