‣‣‣‣‣‣‣‣‣
‣‣    ‣    ‣‣    ‣    ‣
‣
‣    ‣    ‣    ‣    ‣    ‣
‣‣‣‣‣
‣‣‣
‣‣
‣
To invent programs, you need to be able to capture abstractions and ex    design. It’s the job of a programming language t...
‣‣‣
‣‣‣‣    getName()   getName()
‣    ‣    ‣
‣‣‣
‣‣
‣‣
‣‣‣‣‣‣‣‣
‣‣
‣‣‣    ‣    ‣    ‣‣    ‣    ‣
‣‣    ‣    ‣    ‣    ‣    ‣    ‣    ‣    ‣
‣‣    ‣    ‣    ‣‣    ‣    ‣    ‣
‣#pragma once#include "ofMain.h"class Particle {public:!    ofVec2f pos; //    ofVec2f vel; //    ofVec2f frc; // (     ) ...
‣#include "Particle.h"//           (     )Particle::Particle(){!   setInitialCondition(0,0,0,0);!   damping = 0.01f;}//   ...
‣//void Particle::setInitialCondition(float px, float py, float vx, float vy){    pos.set(px,py);!   vel.set(vx,vy);}//voi...
‣‣‣    ‣‣    ‣    ‣    ‣‣    ‣
‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!public:     void setup();     voi...
‣#include "testApp.h"void testApp::setup(){!!   ofSetVerticalSync(true);!   ofSetFrameRate(60);!   ofBackground(0, 0, 0);!...
‣
‣‣    ‣        ‣    ‣        ‣    ‣        ‣    ‣        ‣
‣void testApp::mousePressed(int x, int y, int button){! p.setInitialCondition(x,y,ofRandom(-10,10), ofRandom(-10,10));}
‣
‣‣‣
‣‣‣‣    p[0]    p[1]    p[2]   NUM
‣‣‣Particle p[100];‣‣vector <Particle> p;
‣‣    Particle p[NUM]          p[0]          p[1]          p[2]        NUM         p[NUM]
‣#pragma once#include "ofMain.h"#include "Particle.h"#define NUM 100class testApp : public ofSimpleApp{!public:     void s...
‣#include "testApp.h"void testApp::setup(){!!   ofSetVerticalSync(true);!   ofSetFrameRate(60);!   ofBackground(0, 0, 0);}...
‣void testApp::mousePressed(int x, int y, int button){    for (int i = 0; i < NUM; i++) {        p[i].setInitialCondition(...
‣
‣    Vector <Particle> particles             particles[0]             particles[1]             particles[2]
‣‣‣    particles.push_back(p);‣    particles.pop_back();‣    particles.clear();
‣#pragma once#include "ofMain.h"#include "Particle.h"#define NUM 100class testApp : public ofSimpleApp{!public:     void  ...
‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);}void t...
‣void testApp::mousePressed(int x, int y, int button){    particles.clear();    for (int i = 0; i < NUM; i++) {        //P...
‣
‣‣‣    ‣    ‣    ‣‣
‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!public:     void   setup();     v...
‣#include "testApp.h"void testApp::setup(){!!   ofSetVerticalSync(true);!   ofSetFrameRate(60);!   ofBackground(0, 0, 0);}...
‣void testApp::keyPressed   (int key){!   //c!   if (key == c) {!   !     particles.clear();!   }!   //f!   if (key == f) ...
‣
‣‣‣‣‣‣‣
‣‣‣‣
‣void testApp::draw(){! ofSetColor(255, 255, 255);! //!   string message = "current particle num = "!                    +...
‣
‣‣‣‣‣    ‣    ‣
‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!public:    void setup();    void ...
‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);! ofEna...
‣void testApp::draw(){!   //!   ofSetColor(255, 255, 255);!   string message = "current particle num = " + ofToString(part...
‣void testApp::mouseDragged(int x, int y, int button){! //!   Particle myParticle;!   float vx = ofRandom(-1, 1);!   float...
‣
openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII
openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII
openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII
openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII
Upcoming SlideShare
Loading in …5
×

openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII

10,887 views

Published on

Published in: Technology, Business
  • Be the first to comment

openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII

  1. 1. ‣‣‣‣‣‣‣‣‣
  2. 2. ‣‣ ‣ ‣‣ ‣ ‣
  3. 3.
  4. 4. ‣ ‣ ‣ ‣ ‣ ‣
  5. 5. ‣‣‣‣‣
  6. 6. ‣‣‣
  7. 7. ‣‣
  8. 8.
  9. 9. To invent programs, you need to be able to capture abstractions and ex design. It’s the job of a programming language to help you do this. The process of invention and design by letting you encode abstractions tha It should let you make your ideas concrete in the code you write. Surf the architecture of your program.‣‣ All programming languages provide devices that help express abstrac are ways of grouping implementation details, hiding them, and giving‣ a common interface—much as a mechanical object separates its interfa illustrated in “Interface and Implementation” .‣ Figure 2-1 Inte rfa ce a nd Im ple m e nta tion interface implementation 11 10 9 8 7 6
  10. 10. ‣‣‣
  11. 11. ‣‣‣‣ getName() getName()
  12. 12. ‣ ‣ ‣
  13. 13. ‣‣‣
  14. 14. ‣‣
  15. 15. ‣‣
  16. 16. ‣‣‣‣‣‣‣‣
  17. 17. ‣‣
  18. 18. ‣‣‣ ‣ ‣ ‣‣ ‣ ‣
  19. 19. ‣‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  20. 20. ‣‣ ‣ ‣ ‣‣ ‣ ‣ ‣
  21. 21. ‣#pragma once#include "ofMain.h"class Particle {public:! ofVec2f pos; // ofVec2f vel; // ofVec2f frc; // ( ) float damping; // Particle(); virtual ~Particle(){}; void resetForce(); void addForce(float x, float y); void addDampingForce(); void setInitialCondition(float px, float py, float vx, float vy); void update(); void draw();protected:private:};
  22. 22. ‣#include "Particle.h"// ( )Particle::Particle(){! setInitialCondition(0,0,0,0);! damping = 0.01f;}// ( )void Particle::resetForce(){ frc.set(0,0);}//void Particle::addForce(float x, float y){ frc.x = frc.x + x; frc.y = frc.y + y;}//void Particle::addDampingForce(){ frc.x = frc.x - vel.x * damping; frc.y = frc.y - vel.y * damping;}
  23. 23. ‣//void Particle::setInitialCondition(float px, float py, float vx, float vy){ pos.set(px,py);! vel.set(vx,vy);}//void Particle::update(){!! vel = vel + frc;! pos = pos + vel;}//void Particle::draw(){ ofCircle(pos.x, pos.y, 3);}
  24. 24. ‣‣‣ ‣‣ ‣ ‣ ‣‣ ‣
  25. 25. ‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!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(); // Particle Particle p;};
  26. 26. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);! p.setInitialCondition(ofGetWidth()/2, ofGetHeight()/2, ofRandom(-10,10), ofRandom(-10,10));}void testApp::update(){! p.resetForce();! p.addDampingForce();! p.update();}void testApp::draw(){! ofSetColor(255, 255, 255);! p.draw();}
  27. 27.
  28. 28. ‣‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  29. 29. ‣void testApp::mousePressed(int x, int y, int button){! p.setInitialCondition(x,y,ofRandom(-10,10), ofRandom(-10,10));}
  30. 30.
  31. 31. ‣‣‣
  32. 32. ‣‣‣‣ p[0] p[1] p[2] NUM
  33. 33. ‣‣‣Particle p[100];‣‣vector <Particle> p;
  34. 34. ‣‣ Particle p[NUM] p[0] p[1] p[2] NUM p[NUM]
  35. 35. ‣#pragma once#include "ofMain.h"#include "Particle.h"#define NUM 100class testApp : public ofSimpleApp{!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(); // Particle (NUM ) Particle p[100];};
  36. 36. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);}void testApp::update(){ for (int i = 0; i < NUM; i++) { p[i].resetForce(); p[i].addForce(0, 0.1); p[i].addDampingForce(); p[i].update(); }}void testApp::draw(){! ofSetColor(255, 255, 255); for (int i = 0; i < NUM; i++) { p[i].draw(); }}
  37. 37. ‣void testApp::mousePressed(int x, int y, int button){ for (int i = 0; i < NUM; i++) { p[i].setInitialCondition(x, y, ofRandom(-10,10), ofRandom(-10,10)); }}
  38. 38.
  39. 39. ‣ Vector <Particle> particles particles[0] particles[1] particles[2]
  40. 40. ‣‣‣ particles.push_back(p);‣ particles.pop_back();‣ particles.clear();
  41. 41. ‣#pragma once#include "ofMain.h"#include "Particle.h"#define NUM 100class testApp : public ofSimpleApp{!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(); // Particle particles vector <Particle> particles;};
  42. 42. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);}void testApp::update(){ for (int i = 0; i < particles.size(); i++) { particles[i].resetForce(); particles[i].addForce(0, 0.1); particles[i].addDampingForce(); particles[i].update(); }}void testApp::draw(){! ofSetColor(255, 255, 255); for (int i = 0; i < particles.size(); i++) { particles[i].draw(); }}
  43. 43. ‣void testApp::mousePressed(int x, int y, int button){ particles.clear(); for (int i = 0; i < NUM; i++) { //Particle → myParticle Particle myParticle; // float vx = ofRandom(-10, 10); float vy = ofRandom(-10, 10); myParticle.setInitialCondition(x, y, vx, vy); // particles.push_back(myParticle); }}
  44. 44.
  45. 45. ‣‣‣ ‣ ‣ ‣‣
  46. 46. ‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!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(); // Particle particles vector <Particle> particles;};
  47. 47. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);}void testApp::update(){ for (int i = 0; i < particles.size(); i++) { particles[i].resetForce(); particles[i].addDampingForce(); particles[i].update(); }}void testApp::draw(){! ofSetColor(255, 255, 255);! //! string message = "current particle num = " + ofToString(particles.size(),0);! ofDrawBitmapString(message, 20, 20); for (int i = 0; i < particles.size(); i++) { particles[i].draw(); }}
  48. 48. ‣void testApp::keyPressed (int key){! //c! if (key == c) {! ! particles.clear();! }! //f! if (key == f) {! ! ofToggleFullscreen();! }}void testApp::mouseDragged(int x, int y, int button){! //! Particle myParticle;! float vx = ofRandom(-3, 3);! float vy = ofRandom(-3, 3);! myParticle.setInitialCondition(x, y, vx, vy);! particles.push_back(myParticle);}
  49. 49.
  50. 50. ‣‣‣‣‣‣‣
  51. 51. ‣‣‣‣
  52. 52. ‣void testApp::draw(){! ofSetColor(255, 255, 255);! //! string message = "current particle num = "! + ofToString(particles.size(),0);! ofDrawBitmapString(message, 20, 20);!! ofNoFill();! ofBeginShape();! for (int i = 0; i < particles.size(); i++){! ! ofCurveVertex(particles[i].pos.x, particles[i].pos.y);! }! ofEndShape();}
  53. 53.
  54. 54. ‣‣‣‣‣ ‣ ‣
  55. 55. ‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!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(); // Particle particles vector <Particle> particles;! //! ofImage img;};
  56. 56. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);! ofEnableBlendMode(OF_BLENDMODE_ADD);! //! img.loadImage("particle32.png");}void testApp::update(){ for (int i = 0; i < particles.size(); i++) { particles[i].resetForce(); particles[i].addDampingForce(); particles[i].update(); }}
  57. 57. ‣void testApp::draw(){! //! ofSetColor(255, 255, 255);! string message = "current particle num = " + ofToString(particles.size(),0);! ofDrawBitmapString(message, 20, 20);! //! for (int i = 0; i < particles.size(); i++){! ! float posx = particles[i].pos.x - 16;! ! float posy = particles[i].pos.y - 16;! ! img.draw(posx, posy);! }}void testApp::keyPressed (int key){! //c! if (key == c) {! ! particles.clear();! }! //f! if (key == f) {! ! ofToggleFullscreen();! }}
  58. 58. ‣void testApp::mouseDragged(int x, int y, int button){! //! Particle myParticle;! float vx = ofRandom(-1, 1);! float vy = ofRandom(-1, 1);! myParticle.setInitialCondition(x, y, vx, vy);! particles.push_back(myParticle);}
  59. 59.

×