[ Video ]
[ About ]
本日の日替わりメニュー 円(4個入)
Random walk on circle.
[ 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(39); ofSetColor(239); for (int i = 0; i < 80 * 4; i++) { this->particles.push_back(Particle()); } } //-------------------------------------------------------------- void ofApp::update() { for (Particle& particle : particles) { particle.Upate(); } } //-------------------------------------------------------------- void ofApp::draw() { vector<ofPoint> locations; locations.push_back(ofPoint(-350, -350)); locations.push_back(ofPoint(-350, 350)); locations.push_back(ofPoint(350, -350)); locations.push_back(ofPoint(350, 350)); this->cam.begin(); int count = 0; for (Particle& particle : particles){ ofPushMatrix(); ofTranslate(locations[count++ / 80]); particle.Draw(); ofPopMatrix(); } 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 |
#pragma once #include "ofMain.h" class Particle { public: Particle(); ~Particle(); void Upate(); void Draw(); private: float radius; float deg; ofPoint direction; 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 |
#include "Particle.h" //-------------------------------------------------------------- Particle::Particle() { this->radius = (int)(ofRandom(160, 300) / 20) * 20; this->deg = (int)(ofRandom(360) / 10) * 10; } //-------------------------------------------------------------- Particle::~Particle() { } //-------------------------------------------------------------- void Particle::Upate() { if (ofGetFrameNum() % 20 == 0) { ofPoint directions[4]; directions[0] = ofPoint(1, 0); directions[1] = ofPoint(-1, 0); directions[2] = ofPoint(0, 2); directions[3] = ofPoint(0, -2); if (this->radius <= 160) { directions[3] = directions[2]; } else if (this->radius >= 300) { directions[2] = directions[3]; } this->direction = directions[(int)ofRandom(4)]; } this->deg += this->direction.x; this->radius += this->direction.y; ofPoint point = ofPoint(radius * cos(deg * DEG_TO_RAD), radius * sin(deg * DEG_TO_RAD)); this->logs.push_front(point); while (this->logs.size() > 45) { this->logs.pop_back(); } } //-------------------------------------------------------------- void Particle::Draw() { ofFill(); ofDrawCircle(this->logs.front(), 5); ofNoFill(); ofBeginShape(); for (ofPoint& log : this->logs) { ofVertex(log); } ofEndShape(); } |