[ Video ]
[ About ]
ノイズ関数を使って円を分割
Split circles from Perlin Noise.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#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) {}; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(39); ofNoFill(); ofSetLineWidth(2); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { int span = 144; for (int x = span * 0.5; x < ofGetWidth(); x += span) { for (int y = span * 0.5; y < ofGetHeight(); y += span) { ofPushMatrix(); ofTranslate(x, y); ofRotateDeg(ofRandom(360)); int radius = 60; int deg_span = 1; float noise_seed = ofRandom(1000); vector<int> degs; for (int deg = 0; deg < 180; deg += deg_span) { float noise_value = ofNoise((noise_seed + deg) * 0.04, ofGetFrameNum() * 0.01); if (noise_value > 0.4) { degs.push_back(deg); } else { if (degs.size() > 0) { vector<ofPoint> vertices; for (int i = 0; i < degs.size(); i++) { vertices.push_back(ofPoint(radius * cos(degs[i] * DEG_TO_RAD), radius * sin(degs[i] * DEG_TO_RAD))); } for (int i = degs.size() - 1; i >= 0; i--) { vertices.push_back(ofPoint(radius * cos((360 - degs[i]) * DEG_TO_RAD), radius * sin((360 - degs[i]) * DEG_TO_RAD))); } ofBeginShape(); ofVertices(vertices); ofEndShape(true); degs.clear(); } } } ofPopMatrix(); } } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |