[ Video ]
[ About ]
パーリンノイズ由来の線を六角形でプロット
Draw noise line by 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) {}; float radius; vector<glm::vec2> hex_locations; vector<ofColor> hex_colors; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofEnableBlendMode(ofBlendMode::OF_BLENDMODE_ADD); this->radius = 10; 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 + this->radius * sqrt_3 * 0.5, y); this->hex_locations.push_back(location); ofColor hex_color; hex_color.setHsb(ofRandom(255), 230, 230); this->hex_colors.push_back(hex_color); } flag = !flag; } } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); for (int k = 0; k < 3; k++) { float noise_seed = ofRandom(1000); for (int i = 0; i < this->hex_locations.size(); i++) { auto noise_location = glm::vec2(this->hex_locations[i].x, ofMap(ofNoise(noise_seed, this->hex_locations[i].x * 0.001, ofGetFrameNum() * 0.003), 0, 1, -ofGetHeight() * 0.75, ofGetHeight() * 0.75)); auto distance = glm::distance(this->hex_locations[i], noise_location); if (distance < 60) { ofPushMatrix(); ofTranslate(this->hex_locations[i]); vector<glm::vec2> vertices; for (int deg = 30; deg <= 390; deg += 60) { vertices.push_back(glm::vec2((radius)* cos(deg * DEG_TO_RAD), (radius)* sin(deg * DEG_TO_RAD))); } ofNoFill(); ofSetColor(this->hex_colors[i]); ofBeginShape(); ofVertices(vertices); ofEndShape(true); ofFill(); ofSetColor(this->hex_colors[i], ofMap(distance, 0, 60, 255, 32)); ofBeginShape(); ofVertices(vertices); ofEndShape(true); ofPopMatrix(); } } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |