[ Video ]
[ About ]
上下する六角形。
Updown 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 |
#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) {}; void draw_hexagon(glm::vec2 location, float radius); ofEasyCam cam; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); ofSetLineWidth(3); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); auto radius = 15; auto flag = true; float sqrt_3 = sqrt(3); 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 = flag ? glm::vec2(x, y) : glm::vec2(x + radius * sqrt_3 * 0.5, y); this->draw_hexagon(location, radius); } flag = !flag; } this->cam.end(); } //-------------------------------------------------------------- void ofApp::draw_hexagon(glm::vec2 location, float radius) { ofPushMatrix(); ofTranslate(location); auto noise_value = ofNoise(location.x * 0.05, location.y * 0.05, ofGetFrameNum() * 0.005); auto threshold = 0.68; auto z = 0; auto height = 50; if (noise_value > threshold) { z = ofMap(noise_value, threshold, 1, 0, height); } vector<glm::vec3> vertices, fill_vertices; for (int deg = 30; deg <= 390; deg += 60) { vertices.push_back(glm::vec3(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD), z)); fill_vertices.push_back(glm::vec3(radius * 0.999 * cos(deg * DEG_TO_RAD), radius * sin(deg * 0.999 * DEG_TO_RAD), z)); } ofFill(); ofSetColor(ofMap(z, 0, height, 39, 139)); ofBeginShape(); ofVertices(fill_vertices); ofEndShape(true); ofNoFill(); ofSetColor(ofMap(z, 0, height, 239, 39)); ofBeginShape(); ofVertices(vertices); ofEndShape(true); ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |