[ Video ]
[ About ]
円周から箱が重ならない大きさを計算する。
Calculate the size of the non-overlapping boxes from the circumference.
[ 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) {}; ofEasyCam cam; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(0); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(290); auto small_radius = 0.f; for (auto radius = 50; radius <= 360; radius += small_radius * 2) { auto deg_span = 10; small_radius = (radius * 2 * PI) / 360 * deg_span * 0.5; auto size = (small_radius * 2) / sqrt(3); auto noise_seed = glm::vec3(ofRandom(1000), ofRandom(1000), ofRandom(1000)); auto deg_start = ofGetFrameNum(); for (int deg = deg_start; deg < deg_start + 360; deg += deg_span) { auto location = glm::vec3(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD), 0); auto rotate_x = ofMap(ofNoise(glm::vec4(noise_seed.x, location * 0.0015)), 0, 1, -360, 360); auto rotate_y = ofMap(ofNoise(glm::vec4(noise_seed.y, location * 0.0015)), 0, 1, -360, 360); auto rotate_z = ofMap(ofNoise(glm::vec4(noise_seed.z, location * 0.0015)), 0, 1, -360, 360); ofPushMatrix(); ofTranslate(location); ofRotateZ(rotate_z); ofRotateY(rotate_y); ofRotateX(rotate_x); ofFill(); ofSetColor(0); ofDrawBox(size); ofNoFill(); ofSetColor(255); ofDrawBox(size); ofPopMatrix(); } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |