[ Video ]
[ About ]
六角形でウェーブ
Hexagon wave.
[ 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 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) {}; }; | 
| 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 | #include "ofApp.h"	 //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofSetWindowTitle("openFrameworks"); 	ofBackground(239); } //-------------------------------------------------------------- void ofApp::update() { 	ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { 	ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); 	auto radius = 15; 	auto flg = true; 	float sqrt_3 = sqrt(3); 	int threshold = (ofGetFrameNum() * 3) % 600; 	ofColor color; 	for (float y = -ofGetHeight() * 0.5 - radius; y < ofGetHeight() * 0.5 + radius; y += radius * 1.5) { 		for (float x = -ofGetWidth() * 0.5 - radius; x < ofGetWidth() * 0.5 + radius; x += radius * sqrt_3) { 			auto location = flg ? glm::vec2(x, y) : glm::vec2(x + radius * sqrt_3 * 0.5, y); 			auto len = glm::length(location) + 39; 			auto gap = abs(len - threshold); 			color.setHsb(ofRandom(255), 255, 255); 			if (gap < 39) { 				ofPushMatrix(); 				ofTranslate(location); 				vector<glm::vec2> vertices; 				for (int deg = 30; deg <= 390; deg += 60) { 					vertices.push_back(glm::vec2((radius - 1) * cos(deg * DEG_TO_RAD), (radius - 1) * sin(deg * DEG_TO_RAD))); 				} 				ofNoFill(); 				ofSetColor(color); 				ofBeginShape(); 				ofVertices(vertices); 				ofEndShape(true); 				ofFill(); 				ofSetColor(color, ofMap(gap, 0, 39, 255, 0)); 				ofBeginShape(); 				ofVertices(vertices); 				ofEndShape(true); 				ofPopMatrix(); 			} 		} 		flg = !flg; 	} } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } |