[ Video ]
[ About ]
ノイズ由来のパーティクルの群れ。
Particle Flock.
[ 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(39); ofEnableDepthTest(); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); for (int g = 0; g < 8; g++) { ofPoint parent_seed = ofPoint(ofRandom(100), ofRandom(100), ofRandom(100)); vector<ofPoint> parent_log; int number_of_child = 30; vector<ofPoint> child_seeds; vector<ofColor> child_colors; vector<vector<ofPoint>> child_logs; for (int i = 0; i < number_of_child; i++) { ofPoint child_seed = ofPoint(ofRandom(100), ofRandom(100), ofRandom(100)); child_seeds.push_back(child_seed); ofColor child_color; child_color.setHsb(ofRandom(255), 200, 255); child_colors.push_back(child_color); vector<ofPoint> child_log; child_logs.push_back(child_log); } for (int l = 0; l < 30; l++) { float x = ofMap(ofNoise(parent_seed.x, (ofGetFrameNum() + l) * 0.005), 0, 1, ofGetWidth() * -0.5, ofGetWidth() * 0.5); float y = ofMap(ofNoise(parent_seed.y, (ofGetFrameNum() + l) * 0.005), 0, 1, ofGetHeight() * -0.5, ofGetHeight() * 0.5); float z = ofMap(ofNoise(parent_seed.z, (ofGetFrameNum() + l) * 0.005), 0, 1, ofGetWidth() > ofGetHeight() ? ofGetHeight() : ofGetWidth() * -0.5, ofGetWidth() > ofGetHeight() ? ofGetHeight() : ofGetWidth() * 0.5); ofPoint parent_point = ofPoint(x, y, z); parent_log.push_back(parent_point); for (int i = 0; i < number_of_child; i++) { x = ofMap(ofNoise(child_seeds[i].x, (ofGetFrameNum() + l) * 0.005), 0, 1, -50, 50); y = ofMap(ofNoise(child_seeds[i].y, (ofGetFrameNum() + l) * 0.005), 0, 1, -50, 50); z = ofMap(ofNoise(child_seeds[i].z, (ofGetFrameNum() + l) * 0.005), 0, 1, -50, 50); ofPoint child_point = parent_point + ofPoint(x, y, z); child_logs[i].push_back(child_point); } } ofSetColor(239); ofFill(); ofDrawSphere(parent_log[parent_log.size() - 1], 10); for (int i = 0; i < number_of_child; i++) { for (int l = 0; l < child_logs[i].size() - 1; l++) { ofSetColor(child_colors[i], ofMap(l, 0, child_logs[i].size(), 1, 255)); ofDrawLine(child_logs[i][l], child_logs[i][l + 1]); } ofFill(); ofDrawSphere(child_logs[i][child_logs[i].size() - 1], 5); } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |