[ Video ]
[ About ]
ノイズ関数で変化する4点を結んで四角形を生成。ノイズ関数の引数の増加量をフレーム数で調整して動きに緩急をつけました
Connect the coordinates of 4 points with a line. 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 |
#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; }; |
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); ofSetColor(39); this->noise_seed = 0; } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(10); if (ofGetFrameNum() % 60 < 45) { this->noise_seed += ofMap(ofGetFrameNum() % 60, 0, 45, 0.03, 0); } } //-------------------------------------------------------------- void ofApp::draw() { int span = 120; int range = 100; for (int x = span * 0.5; x < ofGetWidth(); x += span) { for (int y = span * 0.5; y < ofGetHeight(); y += span) { ofPushMatrix(); ofTranslate(x, y); ofFill(); glm::vec2 top_point, prev_point; int number_of_point = 4; for (int i = 0; i < number_of_point; i++) { glm::vec2 point = glm::vec2(ofMap(ofNoise(ofRandom(10000), this->noise_seed), 0, 1, -range * 0.5, range * 0.5), ofMap(ofNoise(ofRandom(10000), this->noise_seed), 0, 1, -range * 0.5, range * 0.5)); ofDrawCircle(point, 5); if (i != 0) { ofDrawLine(prev_point, point); } else { top_point = point; } prev_point = point; } ofDrawLine(top_point, prev_point); ofNoFill(); ofDrawCircle(top_point, 8); ofPopMatrix(); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |