[ Video ]
[ About ]
4つの円を結ぶ。
Connecting circles.
[ 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 windowResized(int w, int h) {}; 	void dragEvent(ofDragInfo dragInfo) {}; 	void gotMessage(ofMessage msg) {}; 	ofMesh mesh; }; | 
| 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 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openframeworks"); 	ofBackground(0); 	ofSetLineWidth(2); 	this->mesh.setMode(OF_PRIMITIVE_LINES); } //-------------------------------------------------------------- void ofApp::update() { 	this->mesh.clear(); 	auto radius = 100; 	auto span = 240; 	int deg_start = ofGetFrameNum() % 360; 	for (auto deg = deg_start; deg < deg_start + 360; deg += 10) { 		this->mesh.addVertex(glm::vec3(span, 0, 0) + glm::vec3(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD), 0)); 		this->mesh.addVertex(glm::vec3(0, -span, 0) + glm::vec3(radius * cos((deg + 90) * DEG_TO_RAD), radius * sin((deg + 90) * DEG_TO_RAD), 0)); 		this->mesh.addVertex(glm::vec3(-span, 0, 0) + glm::vec3(radius * cos((deg + 180) * DEG_TO_RAD), radius * sin((deg + 180) * DEG_TO_RAD), 0)); 		this->mesh.addVertex(glm::vec3(0, span, 0) + glm::vec3(radius * cos((deg + 270) * DEG_TO_RAD), radius * sin((deg + 270) * DEG_TO_RAD), 0)); 		ofColor color; 		for (auto i = 0; i < 4; i++) { 			color.setHsb(ofMap((deg + (360 - deg_start) + i * 180) % 360, 0, 360, 0, 255), 200, 255); 			this->mesh.addColor(color); 		} 		auto index = this->mesh.getVertices().size() - 4; 		this->mesh.addIndex(index); 		this->mesh.addIndex(index + 1); 		this->mesh.addIndex(index + 1); 		this->mesh.addIndex(index + 2); 		this->mesh.addIndex(index + 2); 		this->mesh.addIndex(index + 3); 		this->mesh.addIndex(index + 3); 		this->mesh.addIndex(index + 0); 	} } //-------------------------------------------------------------- void ofApp::draw() { 	ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); 	this->mesh.draw(); 	for (int i = 0; i < this->mesh.getVertices().size(); i++) { 		ofSetColor(this->mesh.getColor(i)); 		ofDrawCircle(this->mesh.getVertex(i), 4); 	} } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } |