[ Video ]
[ About ]
AlminaさんのTeacupsを拝見して、抑えきれない”回したい欲求”が。
Recursive circles.
Teacups
円の中に円を再帰させてみる
遊園地のコーヒーカップみたいなイメージもう一捻り欲しいところ☹️#creativecoding #openframeworks #generative pic.twitter.com/o75f99zXs2
— Almina (@Code4_11) 2019年5月5日
[ 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_circle(glm::vec2 location, float radius, ofColor color, int level); }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetLineWidth(2); ofNoFill(); ofSetCircleResolution(60); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { auto span = 240; for (auto x = span * 0.5; x < ofGetWidth(); x += span) { for (auto y = span * 0.5; y < ofGetHeight(); y += span) { ofPushMatrix(); ofTranslate(x, y); ofColor color; color.setHsb(ofRandom(255), 200, 255); this->draw_circle(glm::vec2(), 100, color, 3); ofPopMatrix(); } } } //-------------------------------------------------------------- void ofApp::draw_circle(glm::vec2 location, float radius, ofColor color, int level) { ofFill(); ofSetColor(color); ofDrawCircle(location, radius); ofNoFill(); ofSetColor(39); ofDrawCircle(location, radius); if (level > 0) { auto small_radius = radius / 4; auto big_radius = small_radius * 3; int deg = ofRandom(360) + ofGetFrameNum() * ofRandom(-3, 3); auto small_location = location - glm::vec2(small_radius * 3 * cos(deg * DEG_TO_RAD), small_radius * 3 * sin(deg * DEG_TO_RAD)); auto big_location = location + glm::vec2(small_radius * cos(deg * DEG_TO_RAD), small_radius * sin(deg * DEG_TO_RAD)); auto small_color = color; small_color.setHsb(((int)color.getHue() + 85) % 255, color.getSaturation(), color.getBrightness()); auto big_color = color; big_color.setHsb(((int)color.getHue() + 170) % 255, color.getSaturation(), color.getBrightness()); this->draw_circle(big_location, big_radius, small_color, level - 1); this->draw_circle(small_location, small_radius, big_color, level - 1); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |