[ Video ]
[ About ]
いびつな球体
An irregular sphere.
[ 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); ofSetLineWidth(2); ofEnableDepthTest(); ofIcoSpherePrimitive ico_sphere = ofIcoSpherePrimitive(250, 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 < 45) { next_point.push_back(this->locations[j]); } } this->next_points.push_back(next_point); } } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); for (int x = -750; x <= 750; x += 750) { for (int y = -750; y <= 750; y += 750) { ofPushMatrix(); ofTranslate(x, y); ofRotateY(ofGetFrameNum() * 0.5); float random_seed = ofRandom(100); for (int location_index = 0; location_index < this->locations.size(); location_index++) { ofPoint location = this->locations[location_index]; float location_noise = ofNoise(random_seed, location.x * 0.005, location.y * 0.005, ofGetFrameNum() * 0.005); if (location_noise > 0.6) { location = location.normalized() * 350; } 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]; float next_noise = ofNoise(random_seed, next_point.x * 0.005, next_point.y * 0.005, ofGetFrameNum() * 0.005); if (next_noise > 0.6) { next_point = next_point.normalized() * 350; } ofDrawLine(location, next_point); } } ofPopMatrix(); } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |