[ Video ]
[ About ]
本日の日替わりメニュー 円柱(愛知県産)
Random walk on cylinder.
[ 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 25 26 |
#pragma once #include "ofMain.h" #include "Particle.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; vector<Particle> particles; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetColor(39); ofEnableDepthTest(); for (int i = 0; i < 512; i++) { this->particles.push_back(Particle()); } } //-------------------------------------------------------------- void ofApp::update() { for (Particle& particle : particles) { particle.Upate(); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); for (Particle& particle : particles) { particle.Draw(); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#pragma once #include "ofMain.h" class Particle { public: Particle(); ~Particle(); void Upate(); void Draw(); private: float radius; float deg; float z; float deg_step; float z_step; std::deque<ofPoint> logs; }; |
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 |
#include "Particle.h" //-------------------------------------------------------------- Particle::Particle() { this->radius = 300; this->deg = (int)(ofRandom(360) / 10) * 10; this->z = (int)(ofRandom(600) / 20) * 20 - 300; } //-------------------------------------------------------------- Particle::~Particle() { } //-------------------------------------------------------------- void Particle::Upate() { if (ofGetFrameNum() % 20 == 0) { int r = ofRandom(4); switch (r) { case 0: this->deg_step = 0.5; this->z_step = 0.0; break; case 1: this->deg_step = -0.5; this->z_step = 0.0; break; case 2: this->deg_step = 0.0; this->z_step = 1.0; break; case 3: this->deg_step = 0.0; this->z_step = -1.0; break; default: this->deg_step = 0.0; this->z_step = 0.0; break; } } if (this->z <= -300) { this->deg_step = 0.0; this->z_step = 1.0; } else if (this->z >= 300) { this->deg_step = 0.0; this->z_step = -1.0; } this->deg += this->deg_step; this->z += this->z_step; ofPoint point = ofPoint(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD), z); this->logs.push_front(point); while (this->logs.size() > 45) { this->logs.pop_back(); } } //-------------------------------------------------------------- void Particle::Draw() { ofFill(); ofDrawSphere(this->logs.front(), 3); ofNoFill(); ofBeginShape(); for (ofPoint& log : this->logs) { ofVertex(log); } ofEndShape(); } |