[ Video ]
[ About ]
宇宙みを目指して。
[ 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" 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 windowResized(int w, int h) {}; 	void dragEvent(ofDragInfo dragInfo) {}; 	void gotMessage(ofMessage msg) {}; 	ofEasyCam cam; 	ofMesh mesh; 	vector<float> radius_list; 	vector<float> speed_list; 	vector<float> deg_list; 	vector<float> deg_speed_list; 	vector<ofColor> color_list; }; | 
| 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 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openframeworks"); 	ofBackground(0); 	ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); 	ofEnableDepthTest(); 	this->mesh.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { 	this->mesh.clear(); 	ofColor color; 	for (int i = 0; i < 5; i++) { 		this->radius_list.push_back(100); 		this->speed_list.push_back(ofRandom(0.5, 1.5)); 		this->deg_list.push_back(ofRandom(360)); 		this->deg_speed_list.push_back(ofRandom(1, 2)); 		color.setHsb(ofRandom(255), 130, 255); 		this->color_list.push_back(color); 	} 	for (int i = this->radius_list.size() - 1; i >= 0; i--) { 		this->radius_list[i] += this->speed_list[i]; 		this->deg_list[i] += this->deg_speed_list[i]; 		this->mesh.addVertex(glm::vec3(this->radius_list[i] * cos(this->deg_list[i] * DEG_TO_RAD), this->radius_list[i] * sin(this->deg_list[i] * DEG_TO_RAD), 0)); 		this->mesh.addColor(this->color_list[i]); 		if (this->radius_list[i] > 450) { 			this->radius_list.erase(this->radius_list.begin() + i); 			this->speed_list.erase(this->speed_list.begin() + i); 			this->deg_list.erase(this->deg_list.begin() + i); 			this->deg_speed_list.erase(this->deg_speed_list.begin() + i); 			this->color_list.erase(this->color_list.begin() + i); 		} 	} 	for (int i = 0; i < this->mesh.getNumVertices(); i++) { 		for (int k = i + 1; k < this->mesh.getNumVertices(); k++) { 			auto distance = glm::distance(this->mesh.getVertex(i), this->mesh.getVertex(k)); 			if (distance < 13) { 				this->mesh.addIndex(i); this->mesh.addIndex(k); 			} 			auto alpha = distance < 10 ? 255 : ofMap(distance, 10, 13, 255, 0); 			if (this->mesh.getColor(i).a < alpha) { 				this->mesh.setColor(i, ofColor(this->mesh.getColor(i), alpha)); 			} 			if (this->mesh.getColor(k).a < alpha) { 				this->mesh.setColor(k, ofColor(this->mesh.getColor(k), alpha)); 			} 		} 	} } //-------------------------------------------------------------- void ofApp::draw() { 	this->cam.begin(); 	ofSetColor(0); 	ofDrawSphere(glm::vec3(), 100); 	for (int i = 0; i < this->mesh.getNumVertices(); i++) { 		ofSetColor(this->mesh.getColor(i)); 		ofDrawSphere(this->mesh.getVertex(i), 1); 	} 	this->mesh.drawWireframe(); 	this->cam.end(); } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } |