[ Video ]
[ About ]
「数学から創るジェネラティブアート」のサンプルDivRectを引用。時間経過でパラメータが変化
Divide rectangle.
[ 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 |
#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_div_rect(glm::vec2 draw_location, int a, int b); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(39); ofSetLineWidth(3); ofNoFill(); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { int span = 180; for (int x = span * 0.5; x < ofGetWidth(); x += span) { for (int y = span * 0.5; y < ofGetHeight(); y += span) { int a = ofMap(ofNoise(ofRandom(100), ofGetFrameNum() * 0.005), 0, 1, 2, 12); int b = ofMap(ofNoise(ofRandom(100), ofGetFrameNum() * 0.005), 0, 1, 2, 12); this->draw_div_rect(glm::vec2(x, y), a, b); } } } //-------------------------------------------------------------- void ofApp::draw_div_rect(glm::vec2 draw_location, int a, int b) { // 数学から創るジェネラティブアート P.51 auto scale = 13; auto width = a * scale; auto height = b * scale; auto length = height; auto location = glm::vec2(); auto count = 0; ofPushMatrix(); ofTranslate(draw_location.x - width * 0.5, draw_location.y - height * 0.5); while (length > 0) { if (count++ % 2 == 0) { while (location.x + length <= width) { ofDrawRectangle(location, length, length); location.x += length; } length = width - location.x; } else { while (location.y + length <= height) { ofDrawRectangle(location, length, length); location.y += length; } length = height - location.y; } } ofPopMatrix(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |