[ Video ]
[ About ]
Day 22 Keys
鍵山をパーリンノイズでユラユラ。動く・止まるの切り替えはフレーム番号によってノイズの引数の値の増加量を調整して実装
Noisy Keys. I changing increase amount of parameter of Perlin Noise from frame number.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#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) {}; float noise_seed; void draw_key(glm::vec2 location, float len); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofSetCircleResolution(30); this->noise_seed = 0; } //-------------------------------------------------------------- void ofApp::update() { int param = ofGetFrameNum() % 60; if (param < 45) { this->noise_seed += ofMap(param, 0, 45, 0.1, 0); } } //-------------------------------------------------------------- void ofApp::draw() { int size = 180; for (int x = size * 0.5; x < ofGetWidth(); x += size) { for (int y = size * 0.5 * 0.8; y < ofGetHeight(); y += size * 0.8) { this->draw_key(glm::vec2(x, y), size); } } } //-------------------------------------------------------------- void ofApp::draw_key(glm::vec2 location, float len) { ofPushMatrix(); ofTranslate(location); ofSetColor(39); ofDrawRectangle(glm::vec2(-len * 0.4, -len * 0.05), len * 0.8, len * 0.1); ofDrawCircle(glm::vec2(len * 0.25, 0), len * 0.2); float noise_value = 0; for (float x = -len * 0.4; x <= -len * 0.2; x += len * 0.05) { noise_value = ofNoise((location.x + x), location.y, this->noise_seed); ofDrawRectangle(glm::vec2(x, len * 0.05), len * 0.05, len * 0.3 * noise_value); } ofSetColor(ofGetBackground()); ofDrawCircle(glm::vec2(len * 0.25, 0) + glm::vec2(len * 0.1 * cos((120 * noise_value - 60) * DEG_TO_RAD), len * 0.1 * sin((120 * noise_value - 60) * DEG_TO_RAD)), len * 0.05); ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |